From c879058007b6e3e659fd71328b6d65e8e9c838e7 Mon Sep 17 00:00:00 2001 From: Felix Boehm <188768+fb55@users.noreply.github.com> Date: Wed, 25 Dec 2024 14:01:44 +0000 Subject: [PATCH] test(attributes): Add tests for missing href prop (#4322) Fixes #4239 --- src/api/attributes.spec.ts | 12 ++++++++++++ src/api/extract.spec.ts | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/src/api/attributes.spec.ts b/src/api/attributes.spec.ts index 9b1c64cbcd..fbea830451 100644 --- a/src/api/attributes.spec.ts +++ b/src/api/attributes.spec.ts @@ -321,6 +321,11 @@ describe('$(...)', () => { expect($(undefined).prop('href')).toBeUndefined(); }); + it('("href") : should skip values without an href', () => { + const $ = load('example1'); + 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('
'); + expect($.root().prop('outerHTML')).toBe( + '
', + ); + }); + it('("innerHTML") : should render properly', () => { const $a = $('
'); diff --git a/src/api/extract.spec.ts b/src/api/extract.spec.ts index b243212710..943b0825f4 100644 --- a/src/api/extract.spec.ts +++ b/src/api/extract.spec.ts @@ -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: [] }); + }); });