![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/lavocat.quebec/private_html/node_modules/cheerio/src/__tests__/ |
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 <media:thumbnail /> tags correctly', () => {
const str =
'<media:thumbnail url="http://www.foo.com/keyframe.jpg" width="75" height="50" time="12:05:01.123" />';
expect(xml(str)).toBe(
'<media:thumbnail url="http://www.foo.com/keyframe.jpg" width="75" height="50" time="12:05:01.123"/>',
);
});
it('should render <link /> tags (RSS) correctly', () => {
const str = '<link>http://www.github.com/</link>';
expect(xml(str)).toBe('<link>http://www.github.com/</link>');
});
it('should escape entities', () => {
const str = '<tag attr="foo & bar"/>';
expect(xml(str)).toBe(str);
});
it('should render HTML as XML', () => {
const $ = load('<foo></foo>', null, false);
expect($.xml()).toBe('<foo/>');
});
});
describe('(dom)', () => {
it('should not keep camelCase for new nodes', () => {
const str = '<g><someElem someAttribute="something">hello</someElem></g>';
expect(dom(str, { xml: false })).toBe(
'<someelem someattribute="something">hello</someelem>',
);
});
it('should keep camelCase for new nodes', () => {
const str = '<g><someElem someAttribute="something">hello</someElem></g>';
expect(dom(str, { xml: true })).toBe(
'<someElem someAttribute="something">hello</someElem>',
);
});
it('should maintain the parsing options of distinct contexts independently', () => {
const str = '<g><someElem someAttribute="something">hello</someElem></g>';
const $ = load('', { xml: false });
expect($(str).html()).toBe(
'<someelem someattribute="something">hello</someelem>',
);
});
});
});