test-utils icon indicating copy to clipboard operation
test-utils copied to clipboard

Plugin provided through nuxtApp.vueApp values are inaccessible in tests

Open mseeley opened this issue 9 months ago • 1 comments

Environment

Stackblitz:

  • Operating System: Linux
  • Node Version: v18.18.0
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6
  • Package Manager: [email protected]
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -

Local:

  • Operating System: Darwin
  • Node Version: v20.11.1
  • Nuxt Version: 3.10.3
  • CLI Version: 3.10.1
  • Nitro Version: 2.8.1
  • Package Manager: [email protected]
  • Builder: -
  • User Config: alias, app, components, css, devServer, devtools, experimental, hooks, googleFonts, ignore, i18n, imports, modules, nitro, router, routeRules, postcss, runtimeConfig, telemetry, typescript, vite
  • Runtime Modules: @nuxtjs/[email protected], @nuxtjs/[email protected], @nuxt/test-utils/[email protected], @pinia/[email protected]
  • Build Modules: -

Reproduction

  • Visit: https://stackblitz.com/edit/github-zqexwa?file=components%2Finject-with-symbol.vue
  • Run npm run test
  • Observe output
    • A value provided using a string injection key is accessible
    • A value provided using a symbol injection key is not accessible

Describe the bug

We have multiple plugins which provide typed values to our Vue app using Symbol inject keys. This works well at runtime.

At test time these provided values are no longer available to inject.

  • Logging demonstrates our plugins are running and providing values to the nuxtApp.vueApp
  • Later logging demonstrates components receive an undefined value

Have we done something wrong? Or, missed some big red text that stable symbols are not guaranteed?

Additional context

I see https://github.com/nuxt/test-utils/commit/fb6f3be64ae66ee43fc4724a0a26f16c97b9e35e is testing a similar case.

Oh, I just found https://github.com/nuxt/test-utils/blob/66c58bc3097246dca015aa293a49ecd5fff0dd11/examples/app-vitest-full/plugins/inject-value.ts#L3

Then I found https://github.com/nuxt/test-utils/issues/750.

I wish this was documented. I would have really liked to have been productive for the last hours.

Logs

No response

mseeley avatar May 04 '24 09:05 mseeley