DEV Community

Discussion on: Testing API calls

Collapse
 
kentcdodds profile image
Kent C. Dodds

Sweet!

You can get rid of the loader test ID by using getByText(/loading/i). And if it's a spinner instead, then you can use aria-label="loading" and getByLabel(/loading/i)

Collapse
 
ryands17 profile image
Ryan Dsouza

Yes that will make it more accessible as well! Thanks a lot :)

Collapse
 
kentcdodds profile image
Kent C. Dodds

Oh, also, you can improve this as well:

let userList = await waitForElement(() => getByRole('list'))

Change that to this:

let userList = await findByRole('list')
Collapse
 
kentcdodds profile image
Kent C. Dodds

And finally, you may like to do this for your assertion:

expect(userList.textContent).toMatchInlineSnapshot()

Jest will auto-update that code to have an inline snapshot for you and you'll get a tiny bit more confidence that it's rendering what it should (without the implementation details of how that text appears on the screen).

Thread Thread
 
ryands17 profile image
Ryan Dsouza

Inline snapshots are great! That's one new arsenal in my tooklit.