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

restoreAllMocks functionality changed in 0.31 #3391

Closed
6 tasks done
silverbackdan opened this issue May 17, 2023 · 2 comments
Closed
6 tasks done

restoreAllMocks functionality changed in 0.31 #3391

silverbackdan opened this issue May 17, 2023 · 2 comments

Comments

@silverbackdan
Copy link

silverbackdan commented May 17, 2023

Describe the bug

It appears that in a test vi.restoreAllMocks() is not restoring mocks back to what I've declared at the head of the file anymore.

Reproduction

This is my test file:
https://github.com/components-web-app/cwa-nuxt-module/blob/nuxt3/src/runtime/storage/stores/fetcher/getters.spec.ts

I get

TypeError: utils.getFetchStatusByToken is not a function
 ❯ ReactiveEffect.fn ../src/runtime/storage/stores/fetcher/getters.ts:31:33
     29|       }
     30| 
     31|       const fetchStatus = utils.getFetchStatusByToken(fetcherState.primaryFetch.successToken)
       |                                 ^
     32|       if (!fetchStatus || utils.isFetchResolving(fetcherState.primaryFetch.successToken)) {
     33|         return
 ❯ ReactiveEffect.run ../node_modules/.pnpm/@vue+reactivity@3.3.2/node_modules/@vue/reactivity/dist/reactivity.cjs.js:182:19
 ❯ ComputedRefImpl.get value [as value] ../node_modules/.pnpm/@vue+reactivity@3.3.2/node_modules/@vue/reactivity/dist/reactivity.cjs.js:1143:33
 ❯ ../src/runtime/storage/stores/fetcher/getters.spec.ts:78:49

and

Error: spyOn could not find an object to spy upon
 ❯ ../src/runtime/storage/stores/fetcher/getters.spec.ts:88:8
     86|     const utils = FetcherGetterUtils.mock.results[0].value
     87|     const expected = returnFetchStatus ? result : undefined
     88|     vi.spyOn(utils, 'getFetchStatusByToken').mockImplementationOnce(() => {
       |        ^
     89|       return expected
     90|     })

On subsequent tests, running each test individually still works fine.

I'm not sure how to make this repro more minimal, but I wanted to raise this first as a package maintainer may immediately know an update that was made that could cause something like this to happen.

System Info

System:
    OS: macOS 12.6
    CPU: (10) arm64 Apple M1 Max
    Memory: 72.34 MB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.16.0 - /usr/local/bin/node
    Yarn: 1.22.19 - ~/.npm-packages/bin/yarn
    npm: 8.11.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 113.0.5672.126
    Safari: 16.0
  npmPackages:
    @vitest/coverage-c8: ^0.30.0 => 0.30.0 
    vitest: 0.31 => 0.31.0 

Used Package Manager

pnpm

Validations

@sheremet-va
Copy link
Member

This was fixed by #3341

@silverbackdan
Copy link
Author

Thank you, sorry I didn't spot this :)

@github-actions github-actions bot locked and limited conversation to collaborators Jun 2, 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

No branches or pull requests

2 participants