Testing · Junior · Question 34 of 78
What does jest.spyOn(obj, "method") / vi.spyOn do?
- ✓Correct answer: Wraps an existing method to record calls; by default it still calls the original
- 2Deletes the method from the object
- 3Copies the object for the test
Explanation
Add .mockImplementation(...) to replace the behaviour, and restore the original with mockRestore() after the test.