You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test('get element by its dynamically assigned value',()=>{const{getByValue, queryByValue, getByTestId}=renderIntoDocument(` <div> <input placeholder="name" type="text" data-testid="name" /> </div> `)getByTestId('name').value='Norris'expect(getByValue('Norris').placeholder).toEqual('name')expect(queryByValue('Norris').placeholder).toEqual('name')})
What you did:
There's an input element (without initial value attribute). I put some value in it with JavaScript.
What happened:
getByValue or queryByValue cannot get the element.
● get element by its dynamically assigned value
Unable to find an element with the value: Norris.
Reproduction:
Problem description:
According to queryAllByAttribute at src/query-helpers.js, it's executing some code like
container.querySelectorAll("[value]")
Since the input element didn't have any value attribute at the first place, this query cannot get it.
Suggested solution:
It should still get input element unless this behaviour is intended.
Querying it with [value] didn't work. Getting value with node.getAttribute("value") didn't work either. So I guess the following code could solve the problem.
The .value setter/getter and the DOM attribute aren't necessarily in sync (see Codepen), so you'd probably need to concat the results of both the current querySelectorAll and the proposed filtered DOM traversal, and maybe dedupe the results with some documented hierarchy (probably preferring the dynamic .value).
dom-testing-library
version: 3.12.4react
version: not using with reactnode
version: 8.11.1npm
(oryarn
) version: npm 5.6.0Relevant code or config:
What you did:
There's an
input
element (without initialvalue
attribute). I put some value in it with JavaScript.What happened:
getByValue
orqueryByValue
cannot get the element.Reproduction:
Problem description:
According to
queryAllByAttribute
atsrc/query-helpers.js
, it's executing some code likeSince the
input
element didn't have anyvalue
attribute at the first place, this query cannot get it.Suggested solution:
It should still get
input
element unless this behaviour is intended.Querying it with
[value]
didn't work. Getting value withnode.getAttribute("value")
didn't work either. So I guess the following code could solve the problem.Let me know what you think!
The text was updated successfully, but these errors were encountered: