Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provides with Symbol not available to rendered component #750

Open
lucasecdb opened this issue Feb 5, 2024 · 5 comments
Open

Provides with Symbol not available to rendered component #750

lucasecdb opened this issue Feb 5, 2024 · 5 comments

Comments

@lucasecdb
Copy link

Environment

  • Operating System: Darwin
  • Node Version: v20.11.0
  • Nuxt Version: 3.10.0
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: [email protected]
  • Builder: -
  • User Config: modules, imports, typescript
  • Runtime Modules: @nuxt/test-utils/[email protected]
  • Build Modules: -

Reproduction

https://github.com/lucasecdb/nuxt-context-error-repro

Describe the bug

Provided value in plugin does not reach the component when using a Symbol() as key.

You can check the behavior by running pnpm test in the MRE. If you run the app using pnpm start and go to http://localhost:3006 you can see the "hello world" string correctly.

image

image

Additional context

No response

Logs

No response

@marcel-wtfoxtrot
Copy link

@lucasecdb

Got the same issue when using vuetify.

Vuetify is using a Symbol internally. Running a test for component which is using a Vuetify Component, the test fails with the following error:

Error: [Vuetify] Could not find defaults instance

Here is a small reproduction repo: https://stackblitz.com/edit/nuxt-starter-7jgbwx?file=vitest.config.ts

@marcel-wtfoxtrot
Copy link

FYI @danielroe

I just had a deeper look into this.

I've added a couple of breakpoints and ran vitest.

Here are a couple of findings:

  1. All Plugins are available within Init Phase (initApp and setup() of nuxt-root)
Screenshot 2024-02-16 at 18 30 26
  1. Plugins seem to be available within setup function of actual component being tested / mounted.
Screenshot 2024-02-16 at 18 31 06
  1. Within the actual inject (vue runtime-core) instance.parent.provides is an empty object. Therefore injection fails / throws.
Screenshot 2024-02-16 at 18 32 23
  1. I also found that within createApp of vue-test-utils's mounting process provides is also on empty object.
Screenshot 2024-02-16 at 18 53 10

I hope this is helpful on finding the cause of this issue. For now i have to go back to @vue/test-utils.

@danielroe
Copy link
Member

danielroe commented Feb 16, 2024

This is probably a regression from #726

@marcel-wtfoxtrot
Copy link

Thank you for this quick response. Also just found this comment within the examples plugin

// TODO: investigate why `Symbol()` export without global registry doesn't match

https://github.com/nuxt/test-utils/blob/main/examples/app-vitest-full/plugins/inject-value.ts#L1

@harunari0928
Copy link

I came up with the ad-hoc solution. Sorry if you already know this.
https://github.com/lucasecdb/nuxt-context-error-repro/pull/1/files

This solution intends that the imported symbol always become same value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants