| Quick Reference Jest CheatsheetJest on one page — matchers, mocks, fake timers, and the traps around toBe, awaits, and spy restore. 10 sections 10 tables 14 code snippets A testActual, then the expected value What runs
This page is the Jest runner. React Testing Library and browser end-to-end tools are left out. MatchersSame fields, different object Identity Which comparison
Thrown errorsPass a function, do not call it What the argument means
PromisesWait for the matcher How a promise is asserted
MocksA fake that records calls Wrap a real method What each stand-in does
Between testsDrop the call history Spies only Clear, reset, restore
Fake timersMove the clock The fake clock
Many rowsOne title, one row Tables and filters
HooksA clean list before each test Scope
Interview trapsAwait the assertion The factory is hoisted Traps worth memorising
How to use this page: pick the matcher for the kind of value, await promises, and restore spies before the next test. |