Async but does it need to be?
Hi,
Thanks for this great site.
This 1st simple test uses
await waitForElement(() => getByText(/hello Satoshi/i))
does it need to use waitForElement? Would getByText alone work? Thanks for the info. John
Good question @harkinj,
Not sure what the right answer is. On one hand waitForElement is more future proof if you use this test as a template for more complicated tests where the text is rendered asynchronously, but on the other hand it makes the simple test look more complicated than it is. There are a few more reasons why I'd keep it:
-
getByTextby itself doesn't look like an assertion. Someone who doesn't understand how RTL works under the hood (I don't!) might think the test is lacking an assertion. - Consistency between tests, not having to think when text is rendered from the start or after async event (especially since component can evolve over time and go from sync to async).
Hi, Thanks for your quick response. As u say its not clear which is better but I take on your points. Thanks again John