The official example about userEvent.selectOptions does not work
Reproduction example
https://codesandbox.io/s/wonderful-meadow-6kth3o?file=/src/App.test.js
Prerequisites
The test will fail while using:
userEvent.selectOptions(screen.getByRole('listbox'), ['1', '3'])
The test will pass while using:
await userEvent.selectOptions(screen.getByRole('listbox'), ['1', '3']);
Expected behavior
The selectOptions() returns a promise, shouldn't the official example use
await userEvent.selectOptions(screen.getByRole('listbox'), ['1', '3']);
Actual behavior
expect(received).toBe(expected) // Object.is equality
Expected: true
Received: false
16 | expect(screen.getByRole('option', {name: 'A'}).selected).toBe(true)
17 | expect(screen.getByRole('option', {name: 'B'}).selected).toBe(false)
> 18 | expect(screen.getByRole('option', {name: 'C'}).selected).toBe(true)
19 | })
User-event version
14.1.1
Environment
Testing Library framework: @testing-library/[email protected]
JS framework: [email protected]
Additional context
The official example about userEvent.selectOptions is here: https://testing-library.com/docs/ecosystem-user-event#selectoptionselement-values-options
The official example about userEvent.selectOptions is here: https://testing-library.com/docs/ecosystem-user-event#selectoptionselement-values-options
The docs might have changed, but I think the v14 example is under User Interaction > Utility APIs; https://testing-library.com/docs/user-event/utility#-selectoptions-deselectoptions
Whereas the link you mention https://testing-library.com/docs/ecosystem-user-event#selectoptionselement-values-options is nested under User Interaction > user-event v13