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

Error with jest-canvas-mock and React.lazy #96

Open
DavidArmendariz opened this issue Jul 1, 2022 · 0 comments
Open

Error with jest-canvas-mock and React.lazy #96

DavidArmendariz opened this issue Jul 1, 2022 · 0 comments

Comments

@DavidArmendariz
Copy link

I am using Lottie to render some animations in React and I am using Jest with React Testing Library. When I test a component like this:

const TestComponent = () => {
  return (
    <div>
      <Lottie animationData={TestAnimation} loop={false} />
    </div>
  );
};

Everything goes fine.

But if I test a component that imports this component via lazy loading like this:

const ComponentThatRendersLottie = lazy(() => import('./ComponentThatRendersLottie'));

const App = () => {

  return (
    <>
      <Suspense fallback={<div />}>
        <Routes>
          <Route element={<ComponentThatRendersLottie />} path="/some-path" />
        </Routes>
      </Suspense>
    </>
  );
};

Then I get an error like this:

Error: Uncaught [TypeError: Cannot set properties of undefined (setting 'fillStyle')]
The above error occurred in one of your React components:
      
     at Lazy
     at ...
     at ...
     ...
React will try to recreate this component tree from scratch using the error boundary you provided, ErrorBoundary.

I am using jest-canvas-mock and just importing it in my setupTest.ts file. I have read their documentation but I haven't found any solution.

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

1 participant