Unit tests that survive refactors

Jest Interview Questions

Mocks, async tests, snapshots, coverage and test design for JavaScript and React codebases.

Quiz me
40 questions10 easy22 medium8 hard0/40 learned
01What is Jest and what does it provide?Easyjest · test runner · tooling02How do you structure a Jest test file?Easytest structure · describe · arrange act assert03How do expect and matchers work in Jest?Easymatchers · assertions · expect04How do describe blocks and hooks work together?Easydescribe · hooks · scoping05What is the full lifecycle of a Jest test?Mediumlifecycle · hooks · ordering06How should you handle setup and teardown in Jest?Mediumsetup · teardown · cleanup07How do mock functions work in Jest?Easymock functions · jest.fn · spies08When do you use jest.fn versus jest.spyOn?Mediumjest.fn · jest.spyOn · mocking09How does jest.mock work and why does hoisting matter?Hardmodule mocking · jest.mock · hoisting10What are manual mocks and when should you use them?Mediummanual mocks · __mocks__ · fixtures11How do you test code that uses timers?Mediumfake timers · timers · async12What are the pitfalls of fake timers?Hardfake timers · pitfalls · async13How do you test asynchronous code in Jest?Mediumasync · await · testing14How do resolves and rejects matchers work?Mediumpromises · resolves · rejects15How does snapshot testing work in Jest?Easysnapshots · regression · serialization16What are the pitfalls of snapshot testing?Mediumsnapshots · brittleness · review17How does code coverage work in Jest?Easycoverage · istanbul · metrics18How do coverage thresholds work and how should you set them?Mediumcoverage · thresholds · quality gates19Why is test isolation important and how do you achieve it?Mediumisolation · state · determinism20What is testEnvironment and when do you change it?MediumtestEnvironment · jsdom · node21What is the difference between the jsdom and node test environments?Mediumjsdom · node environment · dom22How do you test DOM behaviour in Jest?Easydom · testing library · queries23How should you mock network requests in tests?Mediumnetwork · fetch · mocking24How do you use MSW with Jest?Hardmsw · network · integration25How do you write parameterized tests with test.each?Mediumtest.each · table tests · data driven26How does Jest run tests concurrently?Hardconcurrency · workers · maxWorkers27What are the key options in a Jest configuration?Mediumconfiguration · jest.config · projects28How does module resolution work in Jest?MediummoduleNameMapper · paths · resolution29How do transforms work in Jest?Hardtransform · babel · ts-jest30How do you run native ES modules with Jest?Hardesm · modules · configuration31How do you test React components with Jest?Mediumreact · testing library · components32How do you test custom React hooks?Mediumhooks · renderHook · react33How do you test Redux-connected components?Mediumredux · store · integration34How do you test errors and failure paths in Jest?Mediumerrors · toThrow · failure paths35How do you write custom Jest matchers?Mediumcustom matchers · expect.extend · assertions36Can you use Jest for performance testing?Hardperformance · timing · benchmarks37How should Jest run in CI?Mediumci · reproducibility · sharding38How should you name tests and describe blocks?Easynaming · readability · documentation39What are the most common Jest mistakes?Easymistakes · debugging · flakiness40What are the best practices for a healthy Jest suite?Hardbest practices · strategy · test suite

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Jest mock interview and get scored feedback on depth, clarity and confidence.