davidjerleke / embla-carousel

A lightweight carousel library with fluid motion and great swipe precision.
https://www.embla-carousel.com
MIT License
5.37k stars 164 forks source link

[Bug]: Jest testing bug return TypeError: undefined is not a function #837

Closed KareyM closed 2 months ago

KareyM commented 2 months ago

Which variants of Embla Carousel are you using?

Steps to reproduce

When writing test for the EmblaCarousel, i'm getting this error. Not sure what it is that's causing the issue. However, it seem to work just fine within the browser

TypeError: undefined is not a function
        at Array.map (<anonymous>)

      110 |   const DELAY = 4000;
      111 |   const plugins = [EmblaCarouselAutoplay({ delay: DELAY })];
    > 112 |   const emblaApi = EmblaCarousel(emblaNode, options, plugins);
          |                                 ^
      113 |   return emblaApi;
      114 | };
      115 |

Expected Behavior

During a test, calling EmblaCarousel should behave the same work it does during the browser

Additional Context

I'm using the TS version of this and downloaded it through yarn

What browsers are you seeing the problem on?

No response

Version

v8.0.2

CodeSandbox

No response

Before submitting

davidjerleke commented 2 months ago

@KareyM this is not a bug. You need to mock the following API:s to solve the problem:

Feel free to grab the mocks that the core library embla-carousel is using.

Best, David

KareyM commented 2 months ago

Thank you!!