-
ProblemHang out the test that has I use Nx (monorepo), so all tests runs under each libraries. This repo reproduces the issue. vite.config.ts in a library of Nx has Does anyone face a similar issue and have a solution to this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I checked your reproduction and it looks like there's something wrong with // vite.config.ts
server: {
fs: {
allow: [path.join(__dirname, "../..")]
}
}, Another issue (partly on your code) is that you have to use // [not ok]
// const mockedIsOk = vi.fn().mockReturnValue(true);
// [ok]
const mockedIsOk = vi.hoisted(() => vi.fn().mockReturnValue(true))
vi.mock('./isOk', async (importActual) => {
// ...
return {
isOk: mockedIsOk,
};
}); Without browser mode, the wrong code shows |
Beta Was this translation helpful? Give feedback.
I checked your reproduction and it looks like there's something wrong with
server.fs.allow
. Adding this helps getting__vitest_msw__
work:Another issue (partly on your code) is that you have to use
vi.hoisted
to use variables insidevi.mock
Without browser mode, the wrong code shows
ReferenceError: Cannot access 'mockedIsOk' before initialization
, but it looks l…