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
I'm converting a jest setup to vitest and am getting stuck on mocking. In one suite I mock fs with memfs to test some functions that write to disk. My setup is a __mock__ dir with an fs.js file:
import{fs}from"memfs";module.exports=fs;// I've also tried: // export default fs;
and a test file:
import{vi,beforeEach,describe,expect,it,afterEach}from"vitest";import*asfsfrom"fs";import{vol}from"memfs";// a bunch of unrelated imports...vi.mock("fs");// the tests...
If I include vi.mock("fs") vitest is unable to run the tests with the following error: TypeError: Cannot read properties of undefined (reading 'dataEmitted')
Is there something I'm missing about how to mock modules?
P.S. - This fails the same way even if I mock fs with fs itself (i.e. export * as fs from "fs"; so there's something I'm doing wrong in the mocking and not an issue with memfs
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm converting a jest setup to vitest and am getting stuck on mocking. In one suite I mock
fswithmemfsto test some functions that write to disk. My setup is a__mock__dir with anfs.jsfile:and a test file:
If I include
vi.mock("fs")vitest is unable to run the tests with the following error:TypeError: Cannot read properties of undefined (reading 'dataEmitted')Is there something I'm missing about how to mock modules?
P.S. - This fails the same way even if I mock
fswithfsitself (i.e.export * as fs from "fs";so there's something I'm doing wrong in the mocking and not an issue withmemfsBeta Was this translation helpful? Give feedback.
All reactions