
ReactJS
Production mocking patterns.
jest.mock('./utils', () => ({
...jest.requireActual('./utils'),
getUser: jest.fn()
}));
test('uses partial mock', () => {
getUser.mockReturnValue({ name: 'Alice' });
// Other utils functions work normally
});test('handles different responses', () => {
const mockFn = jest.fn()
.mockResolvedValueOnce({ status: 'pending' })
.mockResolvedValueOnce({ status: 'complete' });
expect(await mockFn()).toEqual({ status: 'pending' });
expect(await mockFn()).toEqual({ status: 'complete' });
});jest.mock('./analytics', () => ({
track: jest.fn(),
init: jest.fn()
}));
test('initializes analytics', () => {
import('./analytics').then(module => {
expect(module.init).toHaveBeenCalled();
});
});Resources
Ojasa Mirai
Master AI-powered development skills through structured learning, real projects, and verified credentials. Whether you're upskilling your team or launching your career, we deliver the skills companies actually need.
Learn Deep โข Build Real โข Verify Skills โข Launch Forward