Mock Me — Using Jest’s Mocks for Easier Unit Tests
summary
Jest’s mock primitives let tests avoid real APIs by replacing specific functions or modules: use jest.fn to wrap a function or promise (example returns the pig nose emoji), use jest.mock on an API file or npm dependency (Axios) and set mockReturnValue for resolved data, or use mockImplementation to fake callback APIs like fs so no disk or DB is required. Tests run fast and deterministically in CI while asserting how code handles the mocked responses.
AI-written summary · about
