Follow me on my journey as I write about tech topics I face in my everyday life as a Frontend Developer 💻
Markdown supported · ⌘↵ to post
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
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)