nuxt / nuxt/test-utils

Components tests it is triggering global route middleware

Open
#526 11 comments 16 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

vitest-environment
Dominant language
TypeScript
Stars
437
Forks
120
Avg merge
22h 52m
Merged PRs (30d)
23

Description

When attempting to render a component for a whitebox test, the entire Nuxt environment is being loaded instead of just the component. This behavior is likely caused by the presence of an authentication guard in the project, which leads to redirection to the sign-in page during test execution.

Steps to Reproduce

Access the following StackBlitz link: Reproduction Test

Expected Behavior

The test should only render the targeted component without triggering global route middleware or redirections.

Actual Behavior

Upon running the test, the entire Nuxt environment is loaded, including global route middleware, leading to redirection to the sign-in page due to the presence of the authentication guard.

Additional Information

Nuxt project info:

  • Operating System: Linux
  • Node Version: v18.16.0
  • Nuxt Version: 3.5.3
  • Nitro Version: 2.4.1
  • Package Manager: yarn@3.6.0
  • Builder: vite
  • User Config: alias, app, build, sourcemap, ssr, runtimeConfig, vite, css, modules, components, ignore, dayjs, typescript, experimental, devtools
  • Runtime Modules: dayjs-nuxt@1.1.2, nuxt-vitest@0.10.2, @pinia/nuxt@^0.4.11
  • Build Modules: -

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with test/test.nuxt.spec.ts in the linked StackBlitz reproduction and run the component test with the listed Nuxt and nuxt-vitest versions. Trace why rendering loads the full Nuxt environment and authentication middleware; done means the targeted component renders without global route middleware or sign-in redirection.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxtjs, typescript
Domain
frontend, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.