Yea it's a much more reliable way of checking it. Glad you found it useful. 👍
Getting error in -> ● should allow user to change country.
FAIL src/components/App.test.js
● should allow user to change country
expect(received).toBe(expected) // Object.is equality
Expected: true
Received: false
27 | screen.getByRole('option', {name: 'Ireland'}),
28 | )
> 29 | expect(screen.getByRole('option', {name: 'Ireland'}).selected).toBe(true)
| ^
30 | })
31 |
screen.getByRole('option', { name: 'Ireland' }), for this getting error as multiple elements found out with role options. Throwing error at getByRole not going to the name condition
Ákos Kőműves
Full-Stack Developer and Writer
Thanks for sharing this Cathal Mac Donnacha.
I didn't know I could do
expect(screen.getByRole('option', { name: 'Select a country' }).selected).toBe(true)