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

using createTestingPinia to test components that include storeToRefs results in error #2896

Closed
Ben-Pfirsich opened this issue Jan 24, 2025 · 2 comments

Comments

@Ben-Pfirsich
Copy link

Reproduction

https://github.com/Ben-Pfirsich/testing-pinia-error-example

Steps to reproduce the bug

  1. Check out Example Project
  2. NPM install
  3. call vitest run

Expected behavior

The App.test.ts should pass.
CreateTestingPinia can setup the pinia context for the test.

Test does pass when using Pinia version 2.2.7.

Actual behavior

After upgrading to version 2.2.8 it breaks with the following error:

TypeError: Cannot read properties of undefined (reading 'effect')
    at Module.storeToRefs (file:///C:/DEV/Workspace/test-pinia-error/node_modules/pinia/dist/pinia.mjs:1968:23)
    at setup (C:\DEV\Workspace\test-pinia-error\src\App.vue:7:27)
    at callWithErrorHandling (C:\DEV\Workspace\test-pinia-error\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:200:19)
    at setupStatefulComponent (C:\DEV\Workspace\test-pinia-error\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:7848:25)
    at setupComponent (C:\DEV\Workspace\test-pinia-error\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:7809:36)
    at mountComponent (C:\DEV\Workspace\test-pinia-error\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:5159:7)
    at processComponent (C:\DEV\Workspace\test-pinia-error\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:5125:9)
    at patch (C:\DEV\Workspace\test-pinia-error\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:4654:11)
    at ReactiveEffect.componentUpdateFn [as fn] (C:\DEV\Workspace\test-pinia-error\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:5269:11)
    at ReactiveEffect.run (C:\DEV\Workspace\test-pinia-error\node_modules\@vue\reactivity\dist\reactivity.cjs.js:229:19)

Additional information

Possibly caused by the following change: 67d3109

@posva
Copy link
Member

posva commented Jan 25, 2025

The createSpy should be just vi.fn, not vi.fn()

@posva posva closed this as completed Jan 25, 2025
posva added a commit that referenced this issue Jan 25, 2025
@posva
Copy link
Member

posva commented Jan 25, 2025

I improved the existing warning in 394f655

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

No branches or pull requests

2 participants