Skip to content

Commit

Permalink
Add test cases from #1706
Browse files Browse the repository at this point in the history
Co-Authored-By: 5saviahv <49443574+5saviahv@users.noreply.github.com>
  • Loading branch information
fb55 and 5saviahv committed May 14, 2021
1 parent 043fd85 commit 5a9281b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/api/traversing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,13 @@ describe('$(...)', () => {
expect($selection[0]).toBe($fruits[0]);
expect($selection[1]).toBe($orange[0]);
});
it('is root object preserved', () => {
const $selection = $('<div></div>').add('#fruits');

expect($selection).toHaveLength(2);
expect($selection.eq(0).is('div')).toBe(true);
expect($selection.eq(1).is($fruits.eq(0))).toBe(true);
});
});
describe('(selector) matched elements :', () => {
it('occur before the current selection', () => {
Expand Down
9 changes: 9 additions & 0 deletions src/cheerio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,15 @@ describe('cheerio', () => {
expect(lis).toHaveLength(3);
});

it('should preserve root content', () => {
const $ = cheerio.load(fruits);
// Root should not be overwritten
const el = $('<div></div>');
expect(Object.is(el, el._root)).toBe(false);
// Query has to have results
expect($('li', 'ul')).toHaveLength(3);
});

it('should allow loading a pre-parsed DOM', () => {
const dom = parseDOM(food);
const $ = cheerio.load(dom);
Expand Down

0 comments on commit 5a9281b

Please sign in to comment.