Replies: 5 comments 3 replies
-
We also aren't able to mock
This works though:
|
Beta Was this translation helpful? Give feedback.
-
Just include in your
After that you supposed to be able to use the |
Beta Was this translation helpful? Give feedback.
-
You cannot mock it, |
Beta Was this translation helpful? Give feedback.
-
I also want to mock in vitest, import.meta.client and import.meta.server, these two seems to be read-only values from Nuxt 3. |
Beta Was this translation helpful? Give feedback.
-
Has anyone found a solution? |
Beta Was this translation helpful? Give feedback.
-
Hello, I have a very special mocking question.
We have code, that dynamically imports files with a glob pattern. We use this statement for this:
Now I have to write unit tests for this code. I tried several ways to mock the
import.meta.glob()
call but without success. I tried these options:vi.mock('somewhere/folder/file.js', () => ...)
vi.spyOn(import.meta, 'glob').mockReturnValue(...)
import.meta.glob = vi.fn().mockReturnValue(...)
vi.stubGlobal('import', {meta: {glob: vi.fn().mockReturnValue(...)}})
The last three I executed in a
vi.hoisted()
statement.In any case, the mock did not work. While executing the test,
import.meta.glob()
imported the actual files from the file system.Is there any way to directly mock
import.meta.glob()
?Beta Was this translation helpful? Give feedback.
All reactions