jest mock restore not working code example
Example: jest mock restore
test("mockFn.mockRestore", () => {
const StringUtils = {
toUpperCase(arg) {
return arg && arg.toUpperCase();
}
};
const spy = jest.spyOn(StringUtils, "toUpperCase").mockImplementation(() => "MOCK");
expect(StringUtils.toUpperCase("arg")).toBe("MOCK");
expect(spy).toHaveBeenCalledTimes(1);
expect(jest.isMockFunction(StringUtils.toUpperCase)).toBeTruthy();
spy.mockRestore();
expect(spy("arg")).toBeUndefined();
expect(jest.isMockFunction(StringUtils.toUpperCase)).not.toBeTruthy();
expect(StringUtils.toUpperCase("arg")).toBe("ARG");
expect(spy).toHaveBeenCalledTimes(1);
});