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

mid Level
1
How do you mock functions, modules, and API calls in Jest?
mid
mocking
Jest provides jest.fn() for mock functions, jest.mock() for modules, and jest.spyOn() for spying on methods. For API calls, mock fetch/axios or use libraries like MSW. Mocks isolate code under test and allow controlling dependencies.
2
How do you test React components with React Testing Library?
mid
react-testing-library
React Testing Library tests components from the user's perspective. Use render() to mount components, query methods (getByRole, getByText, etc.) to find elements, fireEvent or userEvent for interactions, and waitFor for async updates.
3
What is the difference between unit tests and integration tests?
mid
integration
Unit tests test individual functions/components in isolation with mocked dependencies. Integration tests verify multiple units work together correctly, testing real interactions between components, APIs, or databases with fewer mocks.
4
What is code coverage and how do you interpret coverage reports?
mid
coverage
Code coverage measures how much source code is executed by tests. Metrics include lines, statements, branches, and functions. High coverage doesn't guarantee quality - focus on testing critical paths and edge cases rather than chasing 100%.
5
How do you test custom React hooks?
mid
hooks
Use @testing-library/react's renderHook to test custom hooks in isolation. The function returns result.current with the hook's return value, and rerender to trigger updates. For hooks with state, use act() to wrap state updates.