Mocking a React higher-order component results in an error #4254
Unanswered
petervmeijgaard
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all!
I'm trying to write a mock for a React higher-order component using
vi.mocked, but I can't seem to get it to workproperly.
Every time I try this, I am greeted with the following error:
However, I have been able to get this working by using
vi.mockat the top of the test, but I need to change the mock abit for each test. Using
vi.mockis not an option, because it will mock the component for all tests the same way.I basically want to mock the HoC like this:
I have been able to reproduce this multiple times and I've created a GitHub repo for you to check out. It can be found here:
https://github.com/petervmeijgaard/vitest-hoc-example/tree/main
The file in question is located at MyComponent.spec.tsx.
I'm using PNPM as a package manager, so be sure to run
pnpm installbefore runningpnpm run test.Thanks for the help!
Beta Was this translation helpful? Give feedback.
All reactions