-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Closed as not planned
Description
Version
29.4.3
Steps to reproduce
Simple test to repro:
describe("mockReset", () => {
const originalReturnValue = "original";
const mockReturnValue = "mocked";
test("spyOn", () => {
const module = { api: () => originalReturnValue };
jest.spyOn(module, "api").mockImplementation(() => mockReturnValue);
expect(module.api()).toStrictEqual(mockReturnValue);
expect(module.api).toHaveBeenCalledTimes(1);
module.api.mockReset();
expect(module.api).toHaveBeenCalledTimes(0);
expect(module.api()).toStrictEqual(undefined);
});
test("overwrite", () => {
const module = { api: () => originalReturnValue };
module.api = jest.fn().mockImplementation(() => mockReturnValue);
expect(module.api()).toStrictEqual(mockReturnValue);
expect(module.api).toHaveBeenCalledTimes(1);
module.api.mockReset();
expect(module.api).toHaveBeenCalledTimes(0);
expect(module.api()).toStrictEqual(undefined);
});
});
Expected behavior
The test should pass where module.api()
is reset to undefined in both the spyOn and overwrite cases.
Actual behavior
The test fails in spyOn case.
● mockReset › spyOn
expect(received).toStrictEqual(expected) // deep equality
Expected: undefined
Received: "original"
13 | expect(module.api).toHaveBeenCalledTimes(0);
14 |
> 15 | expect(module.api()).toStrictEqual(undefined);
| ^
16 | });
Additional context
The fix for resetAllMocks from #13808 should be applied to mockReset too?
Environment
System:
OS: macOS 13.1
CPU: (8) arm64 Apple M1 Pro
Binaries:
Node: 18.13.0 - ~/Library/Caches/fnm_multishells/59531_1676389811348/bin/node
Yarn: 3.4.1 - ~/Library/Caches/fnm_multishells/59531_1676389811348/bin/yarn
npm: 8.19.3 - ~/Library/Caches/fnm_multishells/59531_1676389811348/bin/npm
npmPackages:
jest: ^29.4.3 => 29.4.3