user-event icon indicating copy to clipboard operation
user-event copied to clipboard

The official example about userEvent.selectOptions does not work

Open mrdulin opened this issue 2 years ago • 1 comments

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

mrdulin avatar May 09 '23 07:05 mrdulin

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

chilled-capybara avatar Nov 22 '23 17:11 chilled-capybara