dom-testing-library version: 3.8.2
react version: N/A
node version: v10.11.0 (but it doesn't matter)
npm (or yarn) version: yarn 1.10.1 (but it doesn't matter)
Relevant code or config:
See the reproduction section below.
What you did:
- Created a
<div> containing a <select> with two <option>s.
- Fetched the
<select> using getBySelectText
- Fired a
change event on the fetched <select> to select another valid option
- Verified that the value was changed
- Attempted to fetch the
<select> from the <div> again using the newly selected option's label (child element)
What happened:
The <select> cannot be fetched by its new "select text":
FAIL ./index.test.js
✕ should respond to changes (4520ms)
● should respond to changes
Unable to find a <select> element with the selected option's text: Option 2
<div>
<select>
<option
value="option-1"
>
Option 1
</option>
<option
value="option-2"
>
Option 2
</option>
</select>
</div>
22 | // but this times out because the text hasn't been updated.
23 | // No changes are reflected in the DOM, which is probably why…
> 24 | return waitForElement(() => getBySelectText(container, 'Option 2'));
| ^
25 | });
26 |
at getElementError (node_modules/dom-testing-library/dist/query-helpers.js:29:10)
at getAllBySelectText (node_modules/dom-testing-library/dist/queries.js:375:45)
at firstResultOrNull (node_modules/dom-testing-library/dist/query-helpers.js:37:30)
at getBySelectText (node_modules/dom-testing-library/dist/queries.js:385:42)
at getBySelectText (index.test.js:24:33)
at onMutation (node_modules/dom-testing-library/dist/wait-for-element.js:48:22)
at node_modules/dom-testing-library/dist/wait-for-element.js:66:7
at waitForElement (node_modules/dom-testing-library/dist/wait-for-element.js:26:10)
at Object.waitForElement (index.test.js:24:12)
Reproduction:
const { getBySelectText, fireEvent, wait, waitForElement } = require('dom-testing-library');
it('should respond to changes', () => {
const select = document.createElement('select');
select.innerHTML = `
<option value="option-1">Option 1</option>
<option value="option-2">Option 2</option>
`;
const container = document.createElement('div');
container.appendChild(select);
const foundSelectBeforeEvent = getBySelectText(container, 'Option 1');
expect(foundSelectBeforeEvent.value).toBe('option-1');
fireEvent.change(foundSelectBeforeEvent, { target: { value: 'option-2' }});
// It has been updated, and this passes
expect(foundSelectBeforeEvent.value).toBe('option-2');
// I would then expect to be able to get the <select> again by the new text,
// but this times out because the text hasn't been updated.
// No changes are reflected in the DOM, which is probably why…
return waitForElement(() => getBySelectText(container, 'Option 2'));
});
I've tried (among other things):
waiting for a tick to let updates happen
- Firing events for
focus and blur before and after firing the change to force a rerender
- Not wrapping the fetching in
waitForElement (it just fails in the same way, but faster)
Problem description:
The <select> element doesn't seem to update its displayed value, so it behaves differently from what a user experiences in a browser.
Suggested solution:
The <select> should be selectable using the label of the selected option. I don't know how to fix it, though 😄
dom-testing-libraryversion: 3.8.2reactversion: N/Anodeversion: v10.11.0 (but it doesn't matter)npm(oryarn) version:yarn 1.10.1(but it doesn't matter)Relevant code or config:
See the reproduction section below.
What you did:
<div>containing a<select>with two<option>s.<select>usinggetBySelectTextchangeevent on the fetched<select>to select another valid option<select>from the<div>again using the newly selected option's label (child element)What happened:
The
<select>cannot be fetched by its new "select text":FAIL ./index.test.js ✕ should respond to changes (4520ms) ● should respond to changes Unable to find a <select> element with the selected option's text: Option 2 <div> <select> <option value="option-1" > Option 1 </option> <option value="option-2" > Option 2 </option> </select> </div> 22 | // but this times out because the text hasn't been updated. 23 | // No changes are reflected in the DOM, which is probably why… > 24 | return waitForElement(() => getBySelectText(container, 'Option 2')); | ^ 25 | }); 26 | at getElementError (node_modules/dom-testing-library/dist/query-helpers.js:29:10) at getAllBySelectText (node_modules/dom-testing-library/dist/queries.js:375:45) at firstResultOrNull (node_modules/dom-testing-library/dist/query-helpers.js:37:30) at getBySelectText (node_modules/dom-testing-library/dist/queries.js:385:42) at getBySelectText (index.test.js:24:33) at onMutation (node_modules/dom-testing-library/dist/wait-for-element.js:48:22) at node_modules/dom-testing-library/dist/wait-for-element.js:66:7 at waitForElement (node_modules/dom-testing-library/dist/wait-for-element.js:26:10) at Object.waitForElement (index.test.js:24:12)Reproduction:
I've tried (among other things):
waiting for a tick to let updates happenfocusandblurbefore and after firing thechangeto force a rerenderwaitForElement(it just fails in the same way, but faster)Problem description:
The
<select>element doesn't seem to update its displayed value, so it behaves differently from what a user experiences in a browser.Suggested solution:
The
<select>should be selectable using the label of the selected option. I don't know how to fix it, though 😄