Complete the code to mock a function using Jest.
const myFunc = jest.[1]();The jest.mock() function is used to mock modules, but to mock a function directly, jest.fn() is the correct method.
Complete the code to mock the entire 'fs' module in Jest.
jest.[1]('fs');
To mock an entire module in Jest, you use jest.mock('moduleName').
Fix the error in spying on a method 'readFile' of the 'fs' module.
const fs = require('fs'); jest.[1](fs, 'readFile').mockImplementation((path, cb) => cb(null, 'data'));
To spy on a method of an existing module, jest.spyOn(object, 'method') is used.
Fill both blanks to mock a function and set its return value.
const mockFunc = jest.[1](); mockFunc.[2](() => 42);
You create a mock function with jest.fn() and set its behavior with mockImplementation().
Fill all three blanks to mock a module, spy on a method, and restore the original after test.
jest.[1]('axios'); const axios = require('axios'); const spy = jest.[2](axios, 'get'); // After test spy.[3]();
You mock the module with jest.mock(), spy on a method with jest.spyOn(), and restore the original method with mockRestore().