You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import { describe, expect, it, vi } from "vitest";
const fooService = { foo: () => "foo" };
describe("fooService", () => {
describe("foo", () => {
it("is not a mock functon after 1 spy", () => {
vi.spyOn(fooService, "foo").mockImplementation(() => "bar");
vi.restoreAllMocks();
expect(vi.isMockFunction(fooService.foo)).toBe(false);
});
it("it not a mock function after 2 spys", () => {
vi.spyOn(fooService, "foo").mockImplementation(() => "bar");
vi.spyOn(fooService, "foo").mockImplementation(() => "bar");
vi.restoreAllMocks();
expect(vi.isMockFunction(fooService.foo)).toBe(false);
});
});
});
❯ test/fooService.test.ts (2)
❯ fooService (2)
❯ foo (2)
✓ is not a mock functon after 1 spy
× it not a mock function after 2 spys
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL test/fooService.test.ts > fooService > foo > it not a mock function after 2 spys
AssertionError: expected true to be false // Object.is equality
- Expected
+ Received
- false
+ true
❯ test/fooService.test.ts:15:49
13| vi.spyOn(fooService, "foo").mockImplementation(() => "bar");
14| vi.restoreAllMocks();
15| expect(vi.isMockFunction(fooService.foo)).toBe(false);
| ^
16| });
17| });
I think it's a bug with https://github.com/tinylibs/tinyspy. It restores the previous property decorator, not the original one. Maybe if the property is already spied, we need to return the spy instead of reapplying the spy.
Describe the bug
Spy on an object twice and call
restoreAllMocks
, thenisMockedFunction
still thinks that it is a mock function.Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-bhbdof?file=test%2Fbasic.test.ts
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: