tests are queued but never run
I am trying to add unit tests but vitest would never actually run the tests. Here are the list of relevant files:

16 Replies
Hi @nandi95. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
I'd be happy to help with your Vitest testing issue in Nuxt. Based on the knowledge sources, there could be several reasons why your tests are queued but never run.
Without seeing your specific test files and configuration, I can offer some common solutions based on the information provided:
1. Check your Vitest configuration: Make sure you have the correct configuration for Nuxt. If you're using a
vitest.config.js
file, you might need to rename it or add type: module
to your package.json as mentioned in this PR.
2. Verify test file naming and location: Ensure your test files follow the correct naming convention and are in a location that Vitest can find them.
3. Check for conflicts with Playwright: If you're also using Playwright, there might be conflicts between test runners. As mentioned in this issue, you need to tell Vitest and Playwright which files they are responsible for by putting them in different directories and configuring them accordingly.
4. Verify your test syntax: Make sure you're using the correct imports and test structure. For example:
5. Check for mocking issues: If you're mocking Nuxt composables or other functions, make sure you're doing it correctly. For example, you can use mockNuxtImport()
from 'nuxt-vitest/utils' as mentioned in this Stack Overflow post.
If you could provide more details about your specific setup, test files, and any error messages you're seeing, I could offer more targeted assistance.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@478977928730902528> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
alternatively if I try to run
nuxi test
I get:
that's with the nuxt config:
vitestConfig being an inport from the above file
@kapa.ai re-evaluate with these comments in mind
Let me check the knowledge base for you again. One moment! :books:
----------------------
I'll re-evaluate the issue of Vitest tests being queued but never running based on the knowledge sources provided.
Looking more carefully at the documents, I can see several important insights about testing in Nuxt with Vitest:
1. Mocking issues: One common problem is incorrect mocking of Nuxt's auto-imports. As shown in this Stack Overflow post, you need to mock from the correct package source. For example, instead of mocking from '@vueuse/head', you should use '@unhead/vue' or better yet, use
mockNuxtImport()
from 'nuxt-vitest/utils'.
2. Test environment configuration: Make sure you're using the correct test environment. According to this Stack Overflow post, you might need to explicitly declare the test environment as Nuxt in your Vitest config file.
3. Test runner conflicts: As mentioned in this GitHub issue, if you're using both Vitest and Playwright, you need to ensure they're not trying to run the same test files. Put them in different directories and configure each runner to look only in its specific directory.
4. Proper test setup: When testing components, make sure you're using the correct mounting utilities. For Nuxt components, use mountSuspended
from '@nuxt/test-utils/runtime' as shown in this example.
5. Vitest version compatibility: Recent PRs (#28990 and #28987) show updates to Vitest dependencies, which might indicate compatibility issues with older versions.
If your tests are still not running after addressing these points, you might want to check the Nuxt community resources for help as suggested in the Getting Help documentation. Providing a minimal reproduction of your issue would help others diagnose the problem more effectively.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@478977928730902528> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
it's something to do with the nuxt vitest environment, if I remove that, it works just fine but obviously errors on a nuxt related issue (accessing vueApp)
I see Dan isn't using this vitest nuxt environment: https://github.com/danielroe/roe.dev/blob/main/test/unit/behaviour.spec.ts
GitHub
roe.dev/test/unit/behaviour.spec.ts at main · danielroe/roe.dev
This is the code and content for my personal website, built in Nuxt. - danielroe/roe.dev
No idea, but just in case you didn't know you can challenge kapa more with your new inputs
@kapa.ai it's something to do with the nuxt vitest environment, if I remove that, it works just fine but obviously errors on a nuxt related issue (accessing vueApp)
It seems Dan isn't using this vitest nuxt environment: https://github.com/danielroe/roe.dev/blob/main/test/unit/behaviour.spec.ts
GitHub
roe.dev/test/unit/behaviour.spec.ts at main · danielroe/roe.dev
This is the code and content for my personal website, built in Nuxt. - danielroe/roe.dev
Let me check the knowledge base for you again. One moment! :books:
----------------------
You're right about the Nuxt Vitest environment issue. Looking at the knowledge sources, I can see some insights that might help with your specific problem.
The example you mentioned from Daniel Roe's repository doesn't use the Vitest Nuxt environment directly, which could explain why your tests work when you remove it but then encounter errors with Nuxt-specific features like accessing vueApp.
From the knowledge sources, I can see a few relevant points:
1. There are specific environment packages for Nuxt testing with Vitest. Recent PRs (PR #28571 and PR #28570) show updates to
vitest-environment-nuxt
from version 1.0.0 to 1.0.1, which suggests this is the recommended environment for Nuxt testing.
2. For accessing Nuxt's Vite config in tests, there's a specific approach documented in the Nuxt Kit examples. This might be relevant if your tests need access to the Vite configuration.
3. In issue #31384, there's a workaround for testing issues involving changing the pages directory for tests only:
This approach might help if your issue is related to how Nuxt handles pages during testing.
If you're still having issues, you might want to try:
1. Explicitly configuring the Vitest environment in your config file
2. Checking your Vitest and Nuxt versions for compatibility
3. Creating a minimal reproduction of your issue to share with the Nuxt community
Without seeing your specific configuration and test files, it's difficult to pinpoint the exact issue, but these approaches should help you troubleshoot the problem.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@305772639438503936> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Ah okay
I just found the issue
when using nuxt vitest environment it runs your component in the context of your nuxt app (aka all the bells and whistles). This means in my case the auth middleware when runs makes a request which never completes because nuxt environment? Anyhow vitest happy to sit as long as you keep the process running without a warning 🙃
when changing to jsdom that give me an error that you can only navigate by hashes
@danielroe is this worthy of raising as an issue?
you can use import meta test in your middleware to skip running it in test environments
sure I mean more like the forever going promise
the middleware for reference: