Challenge 2: Choosing the Right Query Prefix — Possible Solution ==================================================================== (a) Confirming an error message is NOT shown before form submission -> queryBy (e.g. queryByText("Invalid email")) Because the element is EXPECTED to be absent, queryBy is required specifically because it returns null instead of throwing when nothing is found. Using getBy here would make the test itself throw an error before the assertion even runs — getBy is built on the assumption the element SHOULD exist, which is the opposite of what's being verified here. The assertion would typically be expect(queryByText("Invalid email")).not.toBeInTheDocument(). (b) Confirming a submit button exists immediately after rendering -> getBy (e.g. getByRole("button", {name: "Submit"})) The button is expected to be present synchronously, right after render() runs, with no waiting involved — exactly this chapter's definition of when getBy is the right choice, since a missing button here represents a genuine, immediate test failure that should throw right away with a clear error. (c) Confirming a "Success!" message appears after an async save completes -> findBy (e.g. findByText("Success!")) The message doesn't exist yet at the moment render() finishes — it only appears later, once an asynchronous operation resolves. findBy is specifically built for this: it returns a Promise and retries the query for a period of time, succeeding once the element eventually appears rather than failing immediately the way getBy would if checked too early.