QuizNot attempted
getBy vs queryBy vs findBy
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
queryByText(...)and expect it to be null
queryBy*returnsnullwhen nothing matches, soexpect(queryByText(...)).toBeNull()(or.not.toBeInTheDocument()) asserts absence cleanly.- Not getByText in try/catch: getBy throws when missing
- catching it hides real errors and reads badly.
- Not findByText: it waits and rejects when missing, slow and meant for things that appear.
- Not getAllByText: also throws when there are zero matches.