JS Guide
HomeQuestionsSearchResources
Search

Built for developers preparing for JavaScript, React & TypeScript interviews.

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionstesting

testing

Unit testing, integration testing, and E2E testing strategies

Your Progress

0 of 5 completed

0%

5 Questions

junior Level
1
What is unit testing and why is it important?
junior
basics
Unit testing involves testing individual units of code (functions, methods, components) in isolation to verify they work correctly. It's important for catching bugs early, enabling safe refactoring, documenting behavior, and building confidence in code quality.
2
What are the most commonly used Jest matchers?
junior
jest
Jest matchers are methods used with expect() to test values. Common ones include toBe() for exact equality, toEqual() for deep equality, toBeTruthy()/toBeFalsy() for boolean checks, toContain() for arrays/strings, and toThrow() for errors.
3
How do you use beforeEach, afterEach, beforeAll, and afterAll in Jest?
junior
setup
These are Jest lifecycle hooks for test setup and cleanup. beforeEach/afterEach run before/after each test. beforeAll/afterAll run once before/after all tests in a describe block. Use them to set up test data, mock functions, or clean up resources.
4
How do you test asynchronous code in Jest?
junior
async
Jest supports testing async code with: async/await (recommended), returning Promises, or using the done callback. For async/await, mark test as async and use await. Always ensure async tests complete properly or they'll timeout.
5
How should you structure and organize test files?
junior
structure
Tests can be organized either alongside source files (Component.test.js) or in a separate __tests__ directory. Use describe blocks to group related tests, clear test names that describe behavior, and follow the Given-When-Then or AAA pattern for clarity.