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

Unable to mock 'vue-meta' #1714

Closed
6 tasks done
jagoncalves14 opened this issue Jul 25, 2022 · 5 comments
Closed
6 tasks done

Unable to mock 'vue-meta' #1714

jagoncalves14 opened this issue Jul 25, 2022 · 5 comments

Comments

@jagoncalves14
Copy link

jagoncalves14 commented Jul 25, 2022

Describe the bug

I was trying to upgrade Vitest from version 0.12.9 to 0.19.0 and now tests that are asserting a specific function from a module to have been called started failing.

That module is an npm package called vue-meta. (Link)
I have components that import { useMeta } from 'vue-meta'.

That useMeta function is called when some components are mounted or created.
All I want to do is to spy useMeta and assert it, expecting that it gets called. Should be easy, right?

But for some reason this stopped working after the upgrade and I'm clueless in understanding why.

I was able to create StackBlitz reproducing this. Just open the link and the test will run automatically.

Reproduction

https://stackblitz.com/edit/vue-vitest-demo

System Info

System:
    OS: macOS 12.4
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 819.89 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.20.0 - ~/.nvm/versions/node/v14.20.0/bin/node
    npm: 8.3.2 - ~/Projects/clearancejobs/node_modules/.bin/npm
  Browsers:
    Chrome: 103.0.5060.134
    Firefox: 100.0
    Safari: 15.5
  npmPackages:
    @vitejs/plugin-vue: 2.1.0 => 2.1.0
    vite: 2.9.9 => 2.9.9
    vitest: 0.19.0 => 0.19.0

Used Package Manager

npm

Validations

@jagoncalves14 jagoncalves14 changed the title Unable to mock one specific function from module Unable to mock 'vue-meta' Jul 25, 2022
@jagoncalves14
Copy link
Author

Note: This started happening in vitest@0.14.2

@sheremet-va
Copy link
Member

sheremet-va commented Jul 31, 2022

It's mention in #1740 that #1726 fixed it, can you confirm? The PR is released with v0.20.0. If so, you can close the issue.

@PatrickChen928
Copy link
Contributor

By my test, it's ok in v0.20.1.

@jagoncalves14
Copy link
Author

@sheremet-va, @ChpShy. Just tested it in both v.0.20.1 and v.0.20.2 and the issue is fixed.

Thanks to everyone involved, that was a super quick fix!
I'm closing the issue as its been resolved.

@luckylooke
Copy link
Contributor

Also unable to mock vue-meta, google brings me here so I am leaving link for my followers. I have find out that now it seems to be unexpected breaking change in vite v3.0.6 more info in dedicated issue.

Happy coding namaste 🙏

@github-actions github-actions bot locked and limited conversation to collaborators Jun 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants