PLAINFINCH learn by building

Every testing term

  • --coverage A flag that makes the runner report which lines and branches ran.
  • .not Flips any matcher so the test checks that something is not true.
  • .rejects Unwraps a promise and checks the error it fails with.
  • .resolves Unwraps a promise and checks the value it settles with.
  • .test.js file A file name ending the runner looks for when it gathers tests to run.
  • accessible name The label a screen reader announces for an element, used by role queries.
  • afterAll() Runs cleanup code once after every test in the file or group is done.
  • afterEach() Runs cleanup code after each test so the next one starts clean.
  • arrange, act, assert A three part shape for tests: set things up, do one action, check the result.
  • assertion A single check inside a test that compares a real result with an expected one.
  • async/await Lets a test wait for a promise to finish before checking what came back.
  • beforeAll() Runs setup code once before any test in the file or group starts.
  • beforeEach() Runs setup code before every test so each one gets fresh data.
  • boundary value An input right at the edge of a rule, where bugs like to hide.
  • branch coverage Tracks whether both sides of every if and else were run by tests.
  • bug report A note describing what went wrong, which you turn into a failing test.
  • coverage A measure of how much of your code actually runs while the tests run.
  • custom error class Your own error type, so tests can check exactly which failure happened.
  • describe() Groups related tests under one heading so results read like an outline.
  • edge case An unusual input, such as empty, zero or huge, that ordinary tests skip.
  • expect() Wraps a value so you can check it with a matcher like toBe or toEqual.
  • expect.arrayContaining() Matches any array that includes the listed items, in any order.
  • expect.assertions() Says how many checks must run, catching async tests that skip them.
  • Expected and Received The two values a failure prints: what the test wanted and what it got.
  • failing test A test that reports a mismatch, which tells you where to look next.
  • failure message The text a runner shows when a test fails, naming the check and the values.
  • fake A simple working stand-in for a real part, like an in-memory store.
  • fake Response A hand-built object that looks like what fetch returns, for use in tests.
  • false pass A test that goes green without really checking anything.
  • flaky test A test that passes sometimes and fails other times with no code change.
  • focused test A test that checks one behavior, so its failure points at one cause.
  • getAllByRole() Finds every element with a given role and returns them as a list.
  • getByLabelText() Finds a form field by the label text a user would read next to it.
  • getByRole() Finds an element by its role, like button or heading, the way users see it.
  • getByTestId() Finds an element by a data-testid attribute, a last resort query.
  • getByText() Finds an element by the visible text inside it.
  • it() Another name for test(), handy when a name reads like a sentence.
  • logic in tests Ifs and loops inside tests, which can hide bugs of their own.
  • mock A fake function that records how it was called so tests can check it.
  • mockRejectedValue() Makes a mock return a promise that fails with the error you give.
  • mockResolvedValue() Makes a mock return a promise that succeeds with the value you give.
  • mockReturnValue() Sets what a mock function hands back each time it is called.
  • mutation Changing an object or array in place, which can surprise other code.
  • mutation testing Breaking code on purpose to see whether any test notices.
  • name option A getByRole option that picks the element with a matching accessible name.
  • no assertion A test with no expect inside, which passes but checks nothing.
  • off-by-one A bug where a count or limit is one too high or one too low.
  • over-mocking Faking so much that a test only checks the fakes, not the real code.
  • query priority The order to prefer queries: role and label first, test ids last.
  • queryBy Queries that return null instead of throwing, used to check something is gone.
  • queryByRole() Looks for an element by role and returns null when there is none.
  • red, green, refactor Write a failing test, make it pass, then tidy the code while it stays green.
  • refactoring Reshaping code without changing what it does, with tests as a safety net.
  • regression A bug where something that used to work breaks after a change.
  • regression test A test written for a fixed bug so the same bug cannot quietly return.
  • reproducing a bug Making a bug happen on demand, ideally inside a failing test.
  • role="alert" Marks a message that screen readers announce at once, easy to find in tests.
  • screen The object holding Testing Library queries for the whole rendered page.
  • shared state Data reused across tests, which lets one test break another.
  • snapshot rot Snapshots updated without reading, until they guard nothing.
  • snapshot test A test that saves output once and fails if it later changes.
  • specification A set of test names that reads as a plain list of what the code does.
  • statement coverage The share of code statements that ran at least once during tests.
  • test A small piece of code that runs your code and checks the result.
  • test helper A small function that builds data or does setup shared by several tests.
  • test isolation Each test runs on its own, so order and other tests never matter.
  • test name A description that says what behavior a test checks and what should happen.
  • test runner The tool that finds your tests, runs them and reports what passed.
  • test suite All the tests for a project, run together to show it still works.
  • test() Defines one test with a name and a function that holds the checks.
  • test-driven development A habit of writing each test before the code that makes it pass.
  • test-first Writing the test before the code, so you know what done looks like.
  • test.each Runs one test body over a table of inputs and expected results.
  • test.only Runs just this test, handy while debugging but risky if left in.
  • test.skip Turns a test off for now while still listing it in the results.
  • test.todo() Lists a test you plan to write, with a name but no body yet.
  • toBe() Checks a value is exactly the same as another, best for numbers and strings.
  • toBeCloseTo() Checks a decimal number is near another, ignoring tiny rounding gaps.
  • toBeDisabled() Checks a button or field cannot be used right now.
  • toBeEnabled() Checks a button or field is ready for the user to use.
  • toBeInTheDocument() Checks an element exists on the rendered page.
  • toBeVisible() Checks an element can actually be seen, not hidden by styles.
  • toContain() Checks an array holds an item or a string holds some text.
  • toEqual() Checks two objects or arrays have the same contents, key by key.
  • toHaveBeenCalledTimes() Checks how many times a mock function was called.
  • toHaveBeenCalledWith() Checks a mock function was called with the arguments you expect.
  • toHaveLength() Checks how many items an array has or how long a string is.
  • toHaveTextContent() Checks the text inside an element matches what you expect.
  • toMatch() Checks a string fits a pattern or contains a piece of text.
  • toMatchInlineSnapshot() Saves a snapshot right inside the test file where you can read it.
  • toMatchObject() Checks an object has the listed keys and values, ignoring any extras.
  • toMatchSnapshot() Saves output to a separate snapshot file and compares later runs to it.
  • toStrictEqual() Like toEqual but also cares about undefined keys and object types.
  • toThrow() Checks that calling a function throws an error, optionally with a message.
  • untested branch A path through an if or switch that no test ever takes.
  • updating snapshots Accepting a new snapshot on purpose after checking the change is right.
  • user.click() Simulates a real user clicking an element, including focus and events.
  • user.keyboard() Simulates pressing keys such as Enter, Escape or Tab.
  • user.selectOptions() Simulates picking one or more choices from a select menu.
  • user.type() Simulates typing text into a field one key at a time.
  • userEvent.setup() Creates a simulated user to drive clicks and typing in a test.
  • vi.advanceTimersByTime() Moves fake time forward so pending timers fire straight away.
  • vi.fn() Creates a mock function that records each call made to it.
  • vi.setSystemTime() Pins the current date to a fixed moment so date code is predictable.
  • vi.spyOn() Watches an existing method's calls, and can swap in a fake version.
  • vi.stubGlobal() Replaces a global like fetch with your own version for the test.
  • vi.useFakeTimers() Swaps real timers for fake ones you can move forward by hand.
  • vi.useRealTimers() Puts the real timers back after a test that used fake ones.
  • Vitest A fast JavaScript test runner with a Jest style way of writing tests.
  • watch mode Reruns your tests every time you save a file.