Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 548 Bytes

checking-for-existence-of-an-element.md

File metadata and controls

21 lines (15 loc) · 548 Bytes

Checking for existence of an element

Use a getBy query combined with the toBeInTheDocument matcher. For example:

expect(screen.getByText('iMac')).toBeInTheDocument();

If the element may take some time to appear, then use the findBy query. Be sure to use await in this case. For example:

expect(await screen.findByText('iMac')).toBeInTheDocument();

If you expect the element to not exist in the document, use the queryBy query. For example:

expect(screen.queryByText('iMac')).not.toBeInTheDocument();