test(attributes): Add tests for missing href prop (#4322)

Fixes #4239
This commit is contained in:
Felix Boehm
2024-12-25 14:01:44 +00:00
committed by GitHub
parent 4d2d51d81e
commit c879058007
2 changed files with 19 additions and 0 deletions

View File

@@ -321,6 +321,11 @@ describe('$(...)', () => {
expect($(undefined).prop('href')).toBeUndefined();
});
it('("href") : should skip values without an href', () => {
const $ = load('<a id="1">example1</a>');
expect($('#1').prop('href')).toBeUndefined();
});
it('("src") : should resolve links with `baseURI`', () => {
const $ = load(
`
@@ -353,6 +358,13 @@ describe('$(...)', () => {
expect($(undefined).prop('outerHTML')).toBeUndefined();
});
it('("outerHTML") : should support root nodes', () => {
const $ = load('<div></div>');
expect($.root().prop('outerHTML')).toBe(
'<html><head></head><body><div></div></body></html>',
);
});
it('("innerHTML") : should render properly', () => {
const $a = $('<div><a></a></div>');

View File

@@ -118,4 +118,11 @@ describe('$.extract', () => {
},
});
});
it('() : should not error on missing href prop (#4239)', () => {
const $ = load(fixtures.eleven);
expect<{ links: string[] }>(
$.extract({ links: [{ selector: 'li', value: 'href' }] }),
).toStrictEqual({ links: [] });
});
});