jest-dom version: 3.5.0const { container } = render(
<form>
<select name="priority">
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="high">High</option>
</select>
</form>
)
const form = container.querySelector('form')
const select = container.querySelector('select')
fireEvent.change(select, { target: { value: 'high' } })
expect(form).toHaveFormValues({ priority: 'high' }) // <- fails here
The above test should pass, but it does not. It fails to recognize the change in the selected value of the select.
After some digging I'm pretty sure this has something to do with the cause of this issue in dom-testing-library. This issue was fixed in this PR, and this is mention in that PR description:
Since
selectedOptionsis not a reactive property, JSDOM was not updating to match the selected option in a select Element. The selected attribute is reactive.
We're using selectedOptions ourselves to check the selected options in a select. See the relevant code.
Maybe following the same approach as testing-library/dom-testing-library#124 and switch to use the select attribute instead.
Hi! I just made a PR to fix this issue. ^
Thank you, you rock :D
:tada: This issue has been resolved in version 4.0.1 :tada:
The release is available on:
npm package (@latest dist-tag)Your semantic-release bot :package::rocket:
Most helpful comment
Hi! I just made a PR to fix this issue. ^