Back to Tech Interviews

Jest JavaScript Testing Interview

Curated 20+ questions covering Jest matchers, async code, snapshot updates, lifecycle hooks, mock utilities, and config options.

Total: 20 QuestionsLearned: 0 / 20 (0%)
Difficulty Filters

Tools & Options
Showing 20 of 20 questions
Beginner
What is Jest, and what are its key advantages?

Jest is a delightful JavaScript testing framework maintained by Meta, designed with a focus on simplicity. Key advantages include: zero configuration out-of-the-box, built-in assertion library, built-in test runner, built-in mocking utilities, snapshot testing, parallel test execution, and fast watch mode.

Beginner
Explain the difference between `toBe()` and `toEqual()` matchers in Jest.

`toBe()` checks for strict identity equality using `Object.is` (compares memory references, like `===`). `toEqual()` checks for value/structural equality, recursively comparing all properties of objects or elements in arrays.

const obj1 = { value: 1 };
const obj2 = { value: 1 };

expect(obj1).toEqual(obj2); // Passes! Structural match
expect(obj1).toBe(obj2);    // Fails! Different memory references
Intermediate
How do you test asynchronous code in Jest?

Jest supports testing async code using three main patterns:

1. Async/Await (Preferred): Write test with `async` and `await` promises.

2. Returning a Promise: Return the promise from the test body; Jest waits for resolution.

3. Using the `done` callback parameter: Call `done()` manually when the async code finishes.

// Async/Await example
test('fetches data', async () => {
  const data = await fetchData();
  expect(data).toBe('success');
});
Intermediate
What is Snapshot Testing, and when should you use it?
Advanced
Explain the difference between `jest.fn()`, `jest.spyOn()`, and `jest.mock()`.
Intermediate
How do you mock an external module (e.g., `axios`) in Jest?
Beginner
What are Jest setup and teardown lifecycle hooks?
Beginner
Explain how to check if a mock function was called.
Intermediate
What is `jest.useFakeTimers()`, and when is it used?
Intermediate
What is a mock implementation vs a mock return value?
Beginner
How do you test that a function throws an error in Jest?
Beginner
What is the Jest configuration file, and what is its default name?
Advanced
What is the difference between `jest.runOnlyPendingTimers()` and `jest.runAllTimers()`?
Beginner
What is the difference between `test()` and `describe()` in Jest?
Advanced
Explain `jest.clearMocks()`, `jest.resetMocks()`, and `jest.restoreMocks()`.
Intermediate
What is the difference between Jest's `node` and `jsdom` test environments?
Intermediate
Explain code coverage configuration in Jest.
Beginner
How do you run a specific single test file in Jest?
Advanced
What is the `mockFn.mock.calls` property?
Advanced
How do you mock modules located in `__mocks__` directory?

Technical Interview Mastery Blueprint

Proven methodologies and frameworks to succeed in technical and architecture rounds.

1. The Engineering STAR Technique

When responding to architectural or situational questions, structure your answer using Situation, Technical Constraint, Action, and Measurable Result. Rather than jumping straight to syntax, articulate the business problem, why certain patterns (e.g. caching, queuing, immutability) were selected over alternatives, and what latency or throughput improvements were achieved.

2. Defending Architectural Trade-Offs

Senior interviewers evaluate how you weigh trade-offs. Always explain why you chose an approach: e.g., memory overhead vs CPU cycle speed, consistency vs availability (CAP theorem), or normalized schemas vs denormalized fast reads. Stating the drawbacks of your own proposal demonstrates maturity and production experience.

3. Clean Code & Edge-Case Proactivity

In live-coding rounds, communicate your thinking aloud before typing. State edge cases explicitly: null or undefined inputs, extreme boundary values, concurrency races, and network timeouts. Writing modular, well-named functions with deterministic unit tests separates junior candidates from staff-level engineers.

4. Antipatterns to Avoid

Avoid reciting memorized definitions without practical context. Never dismiss non-functional requirements such as security (CSRF, injection, token rotation), observability (logging, metrics), and accessibility (ARIA, semantic standards). Always ask clarifying scope questions before writing complex implementations.

Continuous learning: Practice daily, mark completed questions as learned, and revisit difficult concepts.Explore All Interview Tracks →

Explore Related Tools

Hand-picked utilities and calculators related to this tool.

Related Tools