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 when test rendering component using React Test Library #112

Open
wisnuvb opened this issue Sep 28, 2022 · 2 comments
Open

Error when test rendering component using React Test Library #112

wisnuvb opened this issue Sep 28, 2022 · 2 comments

Comments

@wisnuvb
Copy link

wisnuvb commented Sep 28, 2022

I run the test (RTL) getting error TypeError: Cannot read properties of undefined (reading 'prototype') while rendering component.

Screen Shot 2022-09-28 at 15 21 58

I've tried looking everywhere but can't find a solution. I post here to get enlightenment on how to test this component. The screenshot above shows that I immediately called the component, although not directly, the result was still an error. Thanks 🙏

@nextrie
Copy link

nextrie commented Dec 20, 2022

I had the same error, found solution in src/utils/intersection-observer.spec.js:
Adding

window.IntersectionObserver = {};
window.IntersectionObserverEntry = {
  prototype: {
    isIntersecting: () => null,
  },
};

at the beginning of your test or in setupTests fixes the problem.

@washingtonsoares
Copy link

@wisnuvb one other idea is that you can actually mock it in your setupTests.

jest.mock("react-lazy-load-image-component", () => ({
  LazyLoadImage: ({ src, alt }) => <img alt={alt} src={src} />
}));

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

3 participants