How to test a className with the Jest and React testing library

You can easily do that with react-testing-library. First, you have to understand that container or the result of getByText etc. are merely DOM nodes. You can interact with them in the same way you would do in a browser. So, if you want to know what class is applied to container.firstChild you can just do … Read more

How do you test for the non-existence of an element using jest and react-testing-library?

From DOM Testing-library Docs – Appearance and Disappearance Asserting elements are not present The standard getBy methods throw an error when they can’t find an element, so if you want to make an assertion that an element is not present in the DOM, you can use queryBy APIs instead: const submitButton = screen.queryByText(‘submit’) expect(submitButton).toBeNull() // … Read more