Question · JavaScript and TypeScript course · Module 11: Testing with Jest
Difference Between jest.fn() and spyOn
What is the main difference between jest.fn() and jest.spyOn()?
Answer options
- spyOn creates a new function, jest.fn() monitors an existing one
- jest.fn() is faster than spyOn
- jest.fn() creates a new function, spyOn monitors an existing object method
- There is no difference, they are interchangeable
You can check the correct answer by solving this task in the CodeWorlds game.