Skip to content

fix: support getting text of inputs of type reset #1011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/__tests__/element-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,17 @@ test('can get elements by matching their text across adjacent text nodes', () =>
expect(queryByText('£24.99')).toBeTruthy()
})

test('can get input elements with type submit or button', () => {
test('can get input elements with type submit, button, or reset', () => {
const {queryByText} = render(`
<div>
<input type="submit" value="Send data"/>
<input type="reset" value="Clear EVERYTHING"/>
<input type="button" value="Push me!"/>
<input type="text" value="user data" />
</div>
`)
expect(queryByText('Send data')).toBeTruthy()
expect(queryByText('Clear EVERYTHING')).toBeTruthy()
expect(queryByText('Push me!')).toBeTruthy()
expect(queryByText('user data')).toBeFalsy()
})
Expand Down
4 changes: 3 additions & 1 deletion src/get-node-text.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {TEXT_NODE} from './helpers'

function getNodeText(node: HTMLElement): string {
if (node.matches('input[type=submit], input[type=button]')) {
if (
node.matches('input[type=submit], input[type=button], input[type=reset]')
) {
return (node as HTMLInputElement).value
}

Expand Down