Jest is a JavaScript testing framework commonly used for unit and integration testing.
- tests verify expected behavior
- assertions compare expected vs actual
- mocks isolate dependencies
- test runners
- matchers
- spies
- mocks
- snapshots
test("adds numbers", () => {
expect(2 + 2).toBe(4);
});- keep tests small and focused
- test behavior, not implementation details
- mock external dependencies when needed
Supertest is used to test HTTP servers and Express routes.
- sends requests to your app in tests
- checks status codes and responses
- works well with Jest
request(app)
.get("/users")
.expect(200);- useful for API route testing
- good for integration testing of Express endpoints
- often paired with a test database or mock server
React Testing Library focuses on testing components the way users interact with them.
- test what users see and do
- avoid testing internal implementation details when possible
- by text
- by role
- by label text
- by placeholder
- by test id as a fallback
render(<Button />);
screen.getByRole("button", { name: /save/i });- prefer accessible queries
- simulate user behavior
- assert visible outcomes
- keep tests close to real usage