-
Notifications
You must be signed in to change notification settings - Fork 185
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
@fetch-mock/vitest error: Cannot read properties of undefined (reading 'callHistory') #874
Comments
Thanks - a repo would be great, and I'l take a look in the next few days |
Same happens with Jest by the way |
I'm seeing this same thing when using any of the expect(fetchMock).toHave{Verb}ed() helpers. Is there some sort of setup beyond just running fetchMock.mockGlobal().route(...) that I'm missing? |
I just dug into the code, and found that the functions are destructuring fetch-mock/packages/vitest/src/vitest-extensions.ts {
toHaveFetched: (
{ fetchMock }: { fetchMock: FetchMock },
filter: CallHistoryFilter,
options: UserRouteConfig,
): SyncExpectationResult => { /* ... */ }
} So I was able to get my code to work as expected only if I wrapped // importing as documentation describes.
import fetchMock, { manageFetchMockGlobally } from '@fetch-mock/vitest'
expect({ fetchMock }).toHaveFetched('/api/weeks/2020-01-01/rsvp') This is now passing correctly. |
Any news about the types? I am still getting |
@niemisami Are you able to create a repo with a reduced test case that reproduces the issue? |
@wheresrhys Sure here's the demo https://stackblitz.com/edit/vitejs-vite-zjce3ifu?file=src%2Fapp.test.ts Setup I did:
Result is that tests "work" meaning that Sure I'm missing some configuration but I tried to follow vite's and your steps. Thank you for your time |
Setup @fetch-mock/vitest as per documentation and I have two issues:
Property 'toHavePatched' does not exist on type 'Assertion<FetchMockVitest>'
- I didn't see anything in the docs about needing to do a manual override of Vitest types (as described in the Vitest expect extend docs)Cannot read properties of undefined (reading 'callHistory')
:I'll create a repo for reproducing this tomorrow (didn't want to forget to call it out), but I haven't gotten it to work at all yet, so should be pretty easy to reproduce - or maybe I'm missing something?
The text was updated successfully, but these errors were encountered: