import { describe, it, expect } from 'vitest';
import { load } from '../index.js';
import type { CheerioOptions } from '../options.js';
function xml(str: string, options?: CheerioOptions) {
options = { xml: true, ...options };
const $ = load(str, options);
return $.xml();
}
function dom(str: string, options?: CheerioOptions) {
const $ = load('', options);
return $(str).html();
}
describe('render', () => {
describe('(xml)', () => {
it('should render tags correctly', () => {
const str =
'';
expect(xml(str)).toBe(
'',
);
});
it('should render tags (RSS) correctly', () => {
const str = 'http://www.github.com/';
expect(xml(str)).toBe('http://www.github.com/');
});
it('should escape entities', () => {
const str = '';
expect(xml(str)).toBe(str);
});
it('should render HTML as XML', () => {
const $ = load('', null, false);
expect($.xml()).toBe('');
});
});
describe('(dom)', () => {
it('should not keep camelCase for new nodes', () => {
const str = 'hello';
expect(dom(str, { xml: false })).toBe(
'hello',
);
});
it('should keep camelCase for new nodes', () => {
const str = 'hello';
expect(dom(str, { xml: true })).toBe(
'hello',
);
});
it('should maintain the parsing options of distinct contexts independently', () => {
const str = 'hello';
const $ = load('', { xml: false });
expect($(str).html()).toBe(
'hello',
);
});
});
});