|
1 | 1 | 'use strict'; |
2 | 2 | var htmlparser2 = require('htmlparser2'); |
3 | 3 | var cheerio = require('..'); |
| 4 | +var utils = require('../lib/utils'); |
4 | 5 | var fixtures = require('./__fixtures__/fixtures'); |
5 | 6 | var fruits = fixtures.fruits; |
6 | 7 | var food = fixtures.food; |
@@ -64,16 +65,19 @@ describe('cheerio', function () { |
64 | 65 | expect($apple.childNodes[0].data).toBe('Apple'); |
65 | 66 | } |
66 | 67 |
|
| 68 | + // eslint-disable-next-line jest/expect-expect |
67 | 69 | it('should be able to select .apple with only a context', function () { |
68 | 70 | var $apple = cheerio('.apple', fruits); |
69 | 71 | testAppleSelect($apple); |
70 | 72 | }); |
71 | 73 |
|
| 74 | + // eslint-disable-next-line jest/expect-expect |
72 | 75 | it('should be able to select .apple with a node as context', function () { |
73 | 76 | var $apple = cheerio('.apple', cheerio(fruits)[0]); |
74 | 77 | testAppleSelect($apple); |
75 | 78 | }); |
76 | 79 |
|
| 80 | + // eslint-disable-next-line jest/expect-expect |
77 | 81 | it('should be able to select .apple with only a root', function () { |
78 | 82 | var $apple = cheerio('.apple', null, fruits); |
79 | 83 | testAppleSelect($apple); |
@@ -118,16 +122,19 @@ describe('cheerio', function () { |
118 | 122 | }); |
119 | 123 | }); |
120 | 124 |
|
| 125 | + // eslint-disable-next-line jest/expect-expect |
121 | 126 | it('should be able to do: cheerio("#fruits .apple")', function () { |
122 | 127 | var $apple = cheerio('#fruits .apple', fruits); |
123 | 128 | testAppleSelect($apple); |
124 | 129 | }); |
125 | 130 |
|
| 131 | + // eslint-disable-next-line jest/expect-expect |
126 | 132 | it('should be able to do: cheerio("li.apple")', function () { |
127 | 133 | var $apple = cheerio('li.apple', fruits); |
128 | 134 | testAppleSelect($apple); |
129 | 135 | }); |
130 | 136 |
|
| 137 | + // eslint-disable-next-line jest/expect-expect |
131 | 138 | it('should be able to select by attributes', function () { |
132 | 139 | var $apple = cheerio('li[class=apple]', fruits); |
133 | 140 | testAppleSelect($apple); |
@@ -369,4 +376,37 @@ describe('cheerio', function () { |
369 | 376 | }); |
370 | 377 | }); |
371 | 378 | }); |
| 379 | + describe('util functions', function () { |
| 380 | + it('camelCase function test', function () { |
| 381 | + expect(utils.camelCase('cheerio.js')).toBe('cheerioJs'); |
| 382 | + expect(utils.camelCase('camel-case-')).toBe('camelCase'); |
| 383 | + expect(utils.camelCase('__directory__')).toBe('_directory_'); |
| 384 | + expect(utils.camelCase('_one-two.three')).toBe('OneTwoThree'); |
| 385 | + }); |
| 386 | + |
| 387 | + it('cssCase function test', function () { |
| 388 | + expect(utils.cssCase('camelCase')).toBe('camel-case'); |
| 389 | + expect(utils.cssCase('jQuery')).toBe('j-query'); |
| 390 | + expect(utils.cssCase('neverSayNever')).toBe('never-say-never'); |
| 391 | + expect(utils.cssCase('CSSCase')).toBe('-c-s-s-case'); |
| 392 | + }); |
| 393 | + |
| 394 | + it('cloneDom : should be able clone single Elements', function () { |
| 395 | + var main = cheerio('<p>Cheerio</p>'); |
| 396 | + var result = []; |
| 397 | + utils.domEach(main, function (i, el) { |
| 398 | + result = result.concat(utils.cloneDom(el)); |
| 399 | + }); |
| 400 | + expect(result).toHaveLength(1); |
| 401 | + expect(result[0]).not.toBe(main[0]); |
| 402 | + expect(main[0].children.length).toBe(result[0].children.length); |
| 403 | + expect(cheerio(result).text()).toBe(main.text()); |
| 404 | + }); |
| 405 | + |
| 406 | + it('isHtml function test', function () { |
| 407 | + expect(utils.isHtml('<html>')).toBe(true); |
| 408 | + expect(utils.isHtml('\n<html>\n')).toBe(true); |
| 409 | + expect(utils.isHtml('#main')).toBe(false); |
| 410 | + }); |
| 411 | + }); |
372 | 412 | }); |
0 commit comments