nuxt / nuxt/test-utils

[nuxt] instance is not available in server utils unit tests with useRuntimeConfig()

Open
#949 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug pending triage
Dominant language
TypeScript
Stars
437
Forks
120
Avg merge
22h 52m
Merged PRs (30d)
23

Description

Environment
  • Operating System: Darwin
  • Node Version: v20.10.0
  • Nuxt Version: 3.13.2
  • CLI Version: 3.13.2
  • Nitro Version: 2.9.7
  • Package Manager: npm@10.2.3
  • Builder: -
  • User Config: compatibilityDate, devtools, future, experimental, ssr, typescript, routeRules, hooks, runtimeConfig, extends, modules, sourcemap, ui, postcss, tailwindcss, vite, nitro, components, css, imports, content, ogImage, i18n
  • Runtime Modules: @nuxt/test-utils/module@3.14.2, @pinia/nuxt@0.5.4, @nuxt/ui@2.18.4, @nuxtjs/i18n@8.5.3, @nuxt/fonts@0.7.2, @vueuse/nuxt@11.0.3, @nuxt/eslint@0.5.7, nuxt-eslint-auto-explicit-import@0.0.2, @nuxt/image@1.8.0, @nuxtjs/fontaine@0.4.3, @nuxt/content@2.13.2, @codecov/nuxt-plugin@1.0.1, @nuxtjs/seo@2.0.0-rc.21
  • Build Modules: -
Reproduction

https://stackblitz.com/edit/github-gu1sj1-si6cpn?file=server%2Futils%2Fexample-util.nuxt.spec.ts&startScript=start

Run -> npm run test

Describe the bug

After some recent dependancy upgrades around Nuxt I'm getting the [nuxt] instance unavailable error on tests that call functions in server/utils that use useRuntimeConfig.

See the reproduction link for an example. Thanks.

Additional context

No response

Logs

No response

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 the StackBlitz reproduction and server/utils/example-util.nuxt.spec.ts, then run npm run test to reproduce the instance-unavailable error. Compare the failing test setup with the server utility's useRuntimeConfig() call; done means the test runs without the [nuxt] instance unavailable error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.