Jest Assignments — Test. Mock. Ship.

Grow from fundamentals to production-ready testing with topic-wise assignments. Each set includes 20 Basic, 20 Intermediate, and 10 Advanced questions so learners can practice deliberately and level up fast.

These five assignments cover the complete testing toolbelt—from core matchers & async, through mocks, components, timers, GraphQL, all the way to integration/E2E and CI, performance, jest-extended.

Why practice with these assignments?

  • Move beyond theory—write tests, drive UIs, fake time, and mock networks with realistic tasks.
  • Learn mocking patterns (modules, functions, axios/fetch), spies, and snapshot testing across React/Vue/Angular/Next.js.
  • Master timers, debounce/throttle, and GraphQL flows, plus coverage thresholds and watch/CLI filters.
  • Get job-ready with integration & E2E (Playwright/Puppeteer) and CI pipelines (GitHub Actions, artifacts, matrices).

How it works

  • Open any assignment and attempt questions in order: Basic → Intermediate → Advanced.
  • Run the suite (npm test/pnpm test), watch failures, and iterate until green.
  • Use Jest fake timers, mocks, and test runners exactly where the task demands.
  • Keep a short “what I learned” note per problem—this compounds quickly.

What you’ll achieve

  • Strong grasp of matchers, async (callbacks/promises/async-await), and timers.
  • Confidence with mocking (modules, HTTP, DB, interceptors) and spying.
  • Practical component testing across frameworks, plus Redux/Vuex state verification.
  • Ability to run integration/E2E and wire up CI with coverage gates & performance checks.

Who should use this page?

Beginners learning testing, students preparing for interviews, and teams standardizing a modern, reliable testing workflow with Jest.

Browse the Assignments

  • Core Matchers & Async — equality, truthiness, numbers/strings/arrays/objects; callbacks, promises, async/await; CLI filters & coverage.
  • Mocking & UI Tests — jest.fn/spyOn, manual & module mocks, axios/fetch, snapshots; React/Vue/Angular/Next.js basics.
  • Timers, APIs & GraphQL — fake timers, debounce/throttle, REST/axios flows, forms/validation, Apollo MockedProvider; coverage thresholds.
  • Integration & E2E — Redux/Vuex, login flows, Next.js routes, Express+Mongoose, Error Boundaries, Puppeteer/Playwright.
  • CI, Performance & jest-extended — GitHub Actions, artifacts/matrix, perf checks, folder conventions, flaky tests, custom matchers.

Tips for success

  • Start with red → green → refactor; keep tests independent.
  • Prefer async/await for clarity; add timeouts & cancellation where network is mocked.
  • Use fake timers for time-based logic; pair with debounce/throttle tests.
  • Isolate side effects with reset/clear mocks and resetModules for import state.
  • In CI, gate on coverage and surface artifacts for triage; track flakes.

Ready to build real confidence in Jest? Pick a set below and start solving!

FAQs

Q1. Which Jest version and environment should I use?
Use the latest Jest 29+ or 30+ with testEnvironment: "jsdom" for browser-like tests and "node" for server tests. Assignments include both UI and Node flows so you’ll practice switching environments.

Q2. How do I structure tests (unit vs integration vs E2E)?
Keep unit tests near the code, integration tests at feature boundaries (store + component + API), and E2E tests under a dedicated folder. Several tasks explicitly practice all three layers.

Q3. When should I mock vs not mock?
Mock external I/O such as HTTP requests, databases, and time-based APIs, along with expensive dependencies. Do not mock pure utilities—test their real behavior. You’ll use jest.mock, manual mocks, axios/fetch mocks, and interceptors.

Q4. How do I test time-based code reliably?
Enable fake timers, then use advanceTimersByTime or runAllTimers. Cover debounce, throttle, and cancellation paths as separate assertions.

Q5. What’s the recommended way to test React, Vue, or Angular components?
Use each ecosystem’s recommended test utilities such as React Testing Library, Vue Test Utils, or Angular TestBed. You’ll simulate user events, prop updates, error boundaries, and SSR/Next.js data hooks.

Q6. How should I set coverage goals?
Set thresholds in jest.config.js and fail the build if coverage drops below the target. Assignments include enforcing global thresholds and checking branch coverage.

Q7. What’s the difference between clearAllMocks, resetAllMocks, and resetModules?
clearAllMocks clears call history, resetAllMocks also resets mock implementations, and resetModules reloads modules to isolate import state. You’ll apply all three in the assignments.

Q8. How do I handle flaky tests?
Stabilize time and network behavior with mocks, use retryTimes sparingly, and record failures in CI artifacts. There’s a dedicated set on diagnosing flakes and making tests deterministic.

Q9. Do we cover GraphQL and multi-step forms?
Yes. You’ll practice mocked queries and mutations, handling loading, error, and success states, and validating conditional multi-step forms.

Q10. How do I run only certain tests during development?
Use Jest watch filters, --testNamePattern, and --testPathPattern to target specific suites or test cases. This practice appears in the core assignment set.