From f543b0679c292a16faaa393da6e1c11dce4f27f0 Mon Sep 17 00:00:00 2001 From: itutto Date: Mon, 7 Nov 2022 14:10:32 +0100 Subject: [PATCH] #648@patch: OptionElement.value returns `textContent` as fallback. --- .../src/nodes/html-option-element/HTMLOptionElement.ts | 2 +- .../nodes/html-option-element/HTMLOptionElement.test.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/happy-dom/src/nodes/html-option-element/HTMLOptionElement.ts b/packages/happy-dom/src/nodes/html-option-element/HTMLOptionElement.ts index a692e5e00..8a56a4c97 100644 --- a/packages/happy-dom/src/nodes/html-option-element/HTMLOptionElement.ts +++ b/packages/happy-dom/src/nodes/html-option-element/HTMLOptionElement.ts @@ -109,7 +109,7 @@ export default class HTMLOptionElement extends HTMLElement implements IHTMLOptio * @returns Value. */ public get value(): string { - return this.getAttributeNS(null, 'value') || ''; + return this.getAttributeNS(null, 'value') || this.textContent; } /** diff --git a/packages/happy-dom/test/nodes/html-option-element/HTMLOptionElement.test.ts b/packages/happy-dom/test/nodes/html-option-element/HTMLOptionElement.test.ts index dc8769636..679435e8f 100644 --- a/packages/happy-dom/test/nodes/html-option-element/HTMLOptionElement.test.ts +++ b/packages/happy-dom/test/nodes/html-option-element/HTMLOptionElement.test.ts @@ -25,6 +25,12 @@ describe('HTMLOptionElement', () => { element.setAttribute('value', 'VALUE'); expect(element.value).toBe('VALUE'); }); + + it('Returns the text IDL value if no attribute is present.', () => { + element.removeAttribute('value'); + element.textContent = 'TEXT VALUE'; + expect(element.value).toBe('TEXT VALUE'); + }); }); describe('set value()', () => {