Do you have a use case where you need to wait for changes in UI for some time (say, wait for a debounce for 300 ms) before you can test the value change? You can use asyncExpect() instead of using setTimeout()!

Let’s say you have an input field in a page which has a 300ms debounce (which could change in the future) and you need to test whether the input to the field changes the value of the state. One way to solve this is by using setTimeout() in your test like this:

Even though this is a valid solution, it might not necessarily be your best bet because anything that involves a hardcoded time element, can potentially lead to unstable tests. So it is good practice to use asyncExpect() like this: