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

React Testing Library render() not working with embla-carousel-react v8.0.0-rc7 #516

Closed
1 task done
MWhiteFearless opened this issue Jul 6, 2023 · 8 comments
Closed
1 task done
Labels
not a bug This issue is not a bug react Issue is related to React resolved This issue is resolved

Comments

@MWhiteFearless
Copy link

MWhiteFearless commented Jul 6, 2023

Bug is related to

  • embla-carousel-react

Embla Carousel version

  • v8.0.0-rc7

Describe the bug

When upgrading from embla-carousel-react v6.2.0 to v8.0.0-rc7, the tests in my repo for components using embla-carousel-react started failing with the error TypeError: undefined is not a function at Array.map (<anonymous>) when calling render() from react testing library

CodeSandbox

- The link to a CodeSandbox that demonstrates the bug clearly.

Steps to reproduce

  1. Go to Test tab in the sandbox
  2. See that the renders EmblaCarousel test fails with the error
undefined is not a function

TypeError: undefined is not a function
    at Array.map (<anonymous>)
  1. Change the embla-carousel-react version to v7.1.0 and refresh the page, see that the renders EmblaCarousel test passes

Expected behavior

The test should pass and the component should render properly.

@MWhiteFearless MWhiteFearless added the bug Something isn't working label Jul 6, 2023
@MWhiteFearless MWhiteFearless changed the title React Testing Library not working with embla-carousel-react v8.0.0-rc7 React Testing Library render() not working with embla-carousel-react v8.0.0-rc7 Jul 6, 2023
@davidjerleke
Copy link
Owner

Hi @MWhiteFearless,

Thank you for your complete bug report. I will look into this when possible.

Beat,
David

@davidjerleke
Copy link
Owner

davidjerleke commented Jul 7, 2023

Hi @MWhiteFearless,

I haven't investigated this fully but I can think of three things that have changed internally in Embla from v7 --> v8 that can potentially cause problems with React Testing Library:

  • Embla is using window.matchMedia in v8.
  • Embla is using ResizeObserver in v8.
  • Embla is using MutationObserver in v8.
  • Embla is using IntersectionObserver in v8.

So let's say you mock window.matchMedia like this. If you run the tests after that and it starts to work or you get a different error, then I'm probably right about my guess.

Best,
David

@davidjerleke davidjerleke added the investigating Issue is being looked into label Jul 7, 2023
@MWhiteFearless
Copy link
Author

It works by mocking matchMedia! Tests are passing now, thank you! The stackoverflow suggestion worked perfectly for me.

@davidjerleke
Copy link
Owner

@MWhiteFearless I'm glad it solved the problem. So I'm closing this issue then?

Best,
David

@MWhiteFearless
Copy link
Author

Yeah works for me! It could be nice to add a note to the documentation in case others run in to this issue. Really appreciate your help!

@davidjerleke davidjerleke added resolved This issue is resolved react Issue is related to React not a bug This issue is not a bug and removed investigating Issue is being looked into bug Something isn't working labels Jul 7, 2023
@davidjerleke
Copy link
Owner

davidjerleke commented Jul 7, 2023

@MWhiteFearless thanks for the suggestion. I will add it to the breaking changes section in the release notes for the stable v8 release which is coming soon.

@davidjerleke
Copy link
Owner

@raphaelApard see my comment.

@raphaelApard
Copy link

Thanks a lot @MWhiteFearless for completing this issue and @davidjerleke for your responsiveness !
And by the way, thanks for the great work you do with embla-carousel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not a bug This issue is not a bug react Issue is related to React resolved This issue is resolved
Projects
None yet
Development

No branches or pull requests

3 participants