render(<LoginForm />);
// assert here
expect(screen.queryByText(/invalid password/i)).not.toBeInTheDocument()The queryByText option is correct. queryBy* returns null when nothing matches, and not.toBeInTheDocument() accepts null. The tempting getByText option is wrong. getBy* throws when nothing matches, so the test fails before the assertion runs. The findByText option is wrong too. findBy* returns a promise, and a promise is never null.
Read more
- About queries (https://testing-library.com/docs/queries/about)testing-library.com