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
My Problem with nuxt 3 test utils are mainly mocks.
I want to test my reposutory as a basic example.
There is nothing special, its like an composable, which auto imports an other composable "useHttpClient".
also mockNuxtImport lacks of using the real import functionality like
vi.mock(import('./path/to/module.js'), async (importOriginal) => {
const mod = await importOriginal() // type is inferred
return {
...mod,
// replace some exports
total: vi.fn(),
}
})
I also tried it with basic vitest vi mocks. there the mock works but the repository said "useHttpClient" is undefined.
The whole documentation of unit tests in nuxt are very minimalistic, just like the old ones.
Sure some can tell "Skill-Issue", but for real, with all that auto import stuff and layer system, the whole code base becomes a total spaghetti code and nothing stable. Its hard to maintain a stable documentation on that instable architecture, in my opinion.
We need a solid documentation on how to mock imports. Examples with layers.
What I also do not understand. Why are the tsconfig path shortcuts like "~" and "@" not working inside test files
(my tests are under projRoot/tests/unit)
If I add to the tsconfig from proj root the whole import system crashes...
Again, its of course skill-issue but in the nuxt world you cant really built skill because the courses out there show nearly no real world examples of larger architectures and lack in the details.
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
-
My Problem with nuxt 3 test utils are mainly mocks.
I want to test my reposutory as a basic example.
There is nothing special, its like an composable, which auto imports an other composable "useHttpClient".
As outlined in the docs, I tried it with mockNuxtImport. But with that I get the error, that the composable import was not found. But actually it its in the .nuxt/imports.d.ts
https://nuxt.com/docs/getting-started/testing#mocknuxtimport
also mockNuxtImport lacks of using the real import functionality like
I also tried it with basic vitest vi mocks. there the mock works but the repository said "useHttpClient" is undefined.
The whole documentation of unit tests in nuxt are very minimalistic, just like the old ones.
Sure some can tell "Skill-Issue", but for real, with all that auto import stuff and layer system, the whole code base becomes a total spaghetti code and nothing stable. Its hard to maintain a stable documentation on that instable architecture, in my opinion.
We need a solid documentation on how to mock imports. Examples with layers.
What I also do not understand. Why are the tsconfig path shortcuts like "~" and "@" not working inside test files
(my tests are under projRoot/tests/unit)
If I add to the tsconfig from proj root the whole import system crashes...
Again, its of course skill-issue but in the nuxt world you cant really built skill because the courses out there show nearly no real world examples of larger architectures and lack in the details.
Beta Was this translation helpful? Give feedback.
All reactions