import { describe, it, expect, beforeEach } from 'vitest'; import { load, type CheerioAPI } from '../index.js'; import { Cheerio } from '../cheerio.js'; import { type AnyNode, type Element, type Text, isText } from 'domhandler'; import { cheerio, food, fruits, eleven, drinks, text, forms, mixedText, vegetables, } from '../__fixtures__/fixtures.js'; function getText(el: Cheerio) { if (el.length === 0) return undefined; const [firstChild] = el[0].childNodes; return isText(firstChild) ? firstChild.data : undefined; } describe('$(...)', () => { let $: CheerioAPI; beforeEach(() => { $ = load(fruits); }); describe('.load', () => { it('should throw a TypeError if given invalid input', () => { expect(() => { (load as any)(); }).toThrow('cheerio.load() expects a string'); }); }); describe('.find', () => { it('() : should find nothing', () => { expect($('ul').find()).toHaveLength(0); }); it('(single) : should find one descendant', () => { expect($('#fruits').find('.apple')[0].attribs).toHaveProperty( 'class', 'apple', ); }); // #1679 - text tags not filtered it('(single) : should filter out text nodes', () => { const $root = $(`\n${fruits.replace(/>\n<')}\n