JavaScript & TypeScript / Quiz

Queries a User Would Make

getBy vs queryBy vs findBy, role-first locating, and why user-event beats fireEvent. Test the UI the way a human meets it.

Difficulty
Easy
Format
Quiz
Points
100
Estimate
8 min

// MISSION BRIEF

Your Mission

Testing Library's whole philosophy fits in one line: test what the user perceives, not what the DOM tree looks like. The API enforces it, if you know which query to reach for.

This quiz covers the query families (get/query/find), the priority order, multiple-match behavior, and the difference between fireEvent and user-event that decides whether your test exercises real interaction plumbing.

Speed bonus active.

// FIRST CONTACT

Battle teaser

You want to assert that an error banner is NOT on the screen. Which query family is designed for that?

  1. AfindBy*: it resolves to null immediately
  2. BgetBy*: it returns undefined when nothing matches
  3. CAny of them behave identically for absence checks
  4. DqueryBy*: it returns null when nothing matches, so expect(screen.queryByText('Error')).toBeNull() works without throwing
Answers, scoring, hints, and the full battle stay sealed.

// SKILL TAGS

javascripttesting-libraryuser-eventreactunit-testing