Question 5 of 10Pro Only

How do you use mock functions with Jest? Explain jest.fn and jest.mock with examples.

Sample answer preview

Mocking is an essential technique for isolating the code you are testing from its dependencies. Jest provides powerful tools for creating mock functions and modules. jest.fn creates a mock function.

jest.fnjest.mockjest.spyOnmockReturnValuemockResolvedValuetoHaveBeenCalled

Unlock the full answer

Get the complete model answer, key points, common pitfalls, and access to 9+ more Frontend Developer interview questions.

Upgrade to Pro

Starting at $19/month • Cancel anytime