Skip to content

How to test when text changes after user clicks #828

Answered by ph-fritsche
do-kevin asked this question in Q&A
Discussion options

You must be logged in to vote

You hit the test timeout because you await a Promise that is never settled.

await new Promise(() => setTimeout(() => undefined, 500)) // This Promise will never be resolved/rejected.

The test should probably look something like this:

// ...
await userEvent.click(nextAngleButton)

await waitFor(() => { // wait for this function to not throw an error
  expect(serviceHeading).toHaveTextContent('service 2')
})

https://testing-library.com/docs/dom-testing-library/api-async/#waitfor

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@do-kevin
Comment options

Answer selected by do-kevin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants