mirror of
https://github.com/cheeriojs/cheerio.git
synced 2026-02-22 04:41:34 +00:00
feat(attributes): support button value on .val() (#4175)
This commit is contained in:
@@ -93,6 +93,8 @@ export const unwrapspans: string = [
|
||||
].join('');
|
||||
|
||||
export const inputs: string = [
|
||||
'<button id="btn-value" value="button">Button</button>',
|
||||
'<button id="btn-valueless">Button</button>',
|
||||
'<select id="one"><option value="option_not_selected">Option not selected</option><option value="option_selected" selected>Option selected</option></select>',
|
||||
'<select id="one-valueless"><option>Option not selected</option><option selected>Option selected</option></select>',
|
||||
'<select id="one-html-entity"><option>Option not selected</option><option selected>Option <selected></option></select>',
|
||||
|
||||
@@ -652,6 +652,14 @@ describe('$(...)', () => {
|
||||
expect($('<div>').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');
|
||||
@@ -1025,7 +1033,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', () => {
|
||||
|
||||
@@ -811,6 +811,7 @@ export function val<T extends AnyNode>(
|
||||
? option.toArray().map((el) => text(el.children))
|
||||
: option.attr('value');
|
||||
}
|
||||
case 'button':
|
||||
case 'input':
|
||||
case 'option': {
|
||||
return querying
|
||||
|
||||
Reference in New Issue
Block a user