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
Apologies if this is by design, but I couldn't find anywhere that confirms this.
When mocking a module that exports a Class, the expectation is that without passing a factory, that all exports (including the exported Class are automocked).
This seems to work as expected with --environment=jsdom, but when used in --browser=chrome it fails with:
TypeError: Class constructor <name of class> cannot be invoked without 'new'
The error in browser mode can be avoided by supplying a factory to the mock function, e.g. instead of:
vi.mock("./foo.js");
we can pass:
vi.mock("./foo.js",()=>{return{Foo: vi.fn()};});
But it is unclear why this additional boilerplate is only needed in browser mode?
Describe the bug
Apologies if this is by design, but I couldn't find anywhere that confirms this.
When mocking a module that exports a Class, the expectation is that without passing a factory, that all exports (including the exported Class are automocked).
This seems to work as expected with
--environment=jsdom
, but when used in--browser=chrome
it fails with:The error in browser mode can be avoided by supplying a factory to the mock function, e.g. instead of:
we can pass:
But it is unclear why this additional boilerplate is only needed in browser mode?
Reproduction
https://github.com/scottohara/vitest-browser-automock-class
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: