From 2a457d7a8aa96a3fb6a8e0164e7839e0d422ac9d Mon Sep 17 00:00:00 2001 From: kaioduarte Date: Mon, 28 Oct 2024 11:11:38 +0000 Subject: [PATCH] chore: support button value on `.val()` --- src/__fixtures__/fixtures.ts | 2 ++ src/api/attributes.spec.ts | 10 +++++++++- src/api/attributes.ts | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/__fixtures__/fixtures.ts b/src/__fixtures__/fixtures.ts index d153fe2d84..4c902302ab 100644 --- a/src/__fixtures__/fixtures.ts +++ b/src/__fixtures__/fixtures.ts @@ -93,6 +93,8 @@ export const unwrapspans: string = [ ].join(''); export const inputs: string = [ + '', + '', '', '', '', diff --git a/src/api/attributes.spec.ts b/src/api/attributes.spec.ts index 9b1c64cbcd..3a659c602c 100644 --- a/src/api/attributes.spec.ts +++ b/src/api/attributes.spec.ts @@ -640,6 +640,14 @@ describe('$(...)', () => { expect($('
').val()).toBeUndefined(); }); + it('(): on button should get value', () => { + const val = $('#btn-value').val(); + expect(val).toBe('button'); + }); + it('(): on button with no value should get undefined', () => { + const val = $('#btn-valueless').val(); + expect(val).toBeUndefined(); + }); it('(): on select should get value', () => { const val = $('select#one').val(); expect(val).toBe('option_selected'); @@ -1013,7 +1021,7 @@ describe('$(...)', () => { it('(fn) : should no op elements without attributes', () => { const $inputs = $(inputs); const val = $inputs.removeClass(() => 'tasty'); - expect(val).toHaveLength(15); + expect(val).toHaveLength(17); }); it('(fn) : should skip text nodes', () => { diff --git a/src/api/attributes.ts b/src/api/attributes.ts index db246e62b9..cd7cd14f99 100644 --- a/src/api/attributes.ts +++ b/src/api/attributes.ts @@ -797,6 +797,7 @@ export function val( ? option.toArray().map((el) => text(el.children)) : option.attr('value'); } + case 'button': case 'input': case 'option': { return querying