import { describe, it, expect, beforeEach } from 'vitest';
import { load, type Cheerio } from '../index.js';
import type { Element } from 'domhandler';
import { cheerio, mixedText } from '../__fixtures__/fixtures.js';
describe('$(...)', () => {
describe('.css', () => {
it('(prop): should return a css property value', () => {
const el = cheerio('
');
expect(el.css('hai')).toBe('there');
});
it('([prop1, prop2]): should return the specified property values as an object', () => {
const el = cheerio(
'
',
);
expect(el.css(['margin', 'color'])).toStrictEqual({
margin: '1px',
color: 'blue',
});
});
it('(prop, val): should set a css property', () => {
const el = cheerio('
');
el.css('color', 'red');
expect(el.attr('style')).toBe('margin: 0; color: red;');
expect(el.eq(1).attr('style')).toBe('color: red;');
});
it('(prop, val) : should skip text nodes', () => {
const $text = load(mixedText);
const $body = $text($text('body')[0].children);
$body.css('test', 'value');
expect($text('body').html()).toBe(
'1TEXT2',
);
});
it('(prop, ""): should unset a css property', () => {
const el = cheerio('
');
el.css('padding', '');
expect(el.attr('style')).toBe('margin: 0;');
});
it('(any, val): should ignore unsupported prop types', () => {
const el = cheerio('
');
el.css(123 as never, 'test');
expect(el.attr('style')).toBe('padding: 1px;');
});
it('(prop): should not mangle embedded urls', () => {
const el = cheerio(
'
',
);
expect(el.css('background-image')).toBe(
'url(http://example.com/img.png)',
);
});
it('(prop): should ignore blank properties', () => {
const el = cheerio('
');
expect(el.css()).toStrictEqual({ color: '#aaa' });
});
it('(prop): should ignore blank values', () => {
const el = cheerio('
');
expect(el.css()).toStrictEqual({ position: 'absolute' });
});
it('(prop): should return undefined for unmatched elements', () => {
const $ = load('
');
expect($('ul').css('background-image')).toBeUndefined();
});
it('(prop): should return undefined for unmatched styles', () => {
const el = cheerio('