We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
instanceof
I think there is a combination of things going on here.
Mocking of modules with classes works with tinyspy 1.0.2 but breaks with tinyspy 1.1.0.
1.0.2
1.1.0
See: tinylibs/tinyspy#32
Looks like the prototype chain isn't getting preserved.
import { afterEach, describe, expect, test, vi } from 'vitest'; import { MyClass } from './MyClass.js'; import { create, isMyClass } from './MyClassUtil.js'; vi.mock('./MyClass.js'); const mockedMyClass = vi.mocked(MyClass); // class MockImplementationMyClass { // constructor(readonly name: string) {} // } // mockedMyClass.mockImplementation((name) => new MockImplementationMyClass(name)); describe('MyClass', () => { afterEach(() => { mockedMyClass.mockClear(); }); test.each` name | expected ${'Atlantic'} | ${'Atlantic'} ${'Pacific'} | ${'Pacific'} `('new MyClass $name', ({ name, expected }) => { const instance = create(name); expect(isMyClass(instance)).toBe(true); // Breaks here expect(instance).toBeInstanceOf(MyClass); // And here expect(mockedMyClass).toHaveBeenCalledTimes(1); expect(mockedMyClass).toHaveBeenCalledWith(expected); }); });
https://stackblitz.com/edit/vitest-dev-vitest-dhhorq?file=README.md
System: OS: Linux 5.0 undefined CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 16.14.2 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 7.17.0 - /usr/local/bin/npm npmPackages: @vitest/ui: latest => 0.28.4 vite: ^4.1.1 => 4.1.1 vitest: ^0.26.3 => 0.26.3
pnpm
The text was updated successfully, but these errors were encountered:
This is fixed in tinylibs/tinyspy#32
Sorry, something went wrong.
No branches or pull requests
Describe the bug
I think there is a combination of things going on here.
Mocking of modules with classes works with tinyspy
1.0.2
but breaks with tinyspy1.1.0
.See: tinylibs/tinyspy#32
Looks like the prototype chain isn't getting preserved.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-dhhorq?file=README.md
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: