Skip to content

Commit

Permalink
test(attributes): Add tests for missing href prop
Browse files Browse the repository at this point in the history
Fixes #4239
  • Loading branch information
fb55 committed Dec 25, 2024
1 parent 4d2d51d commit 1b29bdb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/api/attributes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
`
Expand Down Expand Up @@ -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>');

Expand Down
7 changes: 7 additions & 0 deletions src/api/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] });
});
});

0 comments on commit 1b29bdb

Please sign in to comment.