Replies: 4 comments 9 replies
-
|
check out my answer to the other question about testing swiper components, let me know if that fixes it: |
Beta Was this translation helpful? Give feedback.
-
|
Hey having the same issue have you fond a solution? |
Beta Was this translation helpful? Give feedback.
-
|
Also unable to run tests with this. React 18, Next.js 12, Swiper 8, Jest 27 |
Beta Was this translation helpful? Give feedback.
-
|
Solution for Swiper v10+ (ESM-only) Since Swiper v10 is ESM-only, Jest can't resolve its modules directly. The workaround is to redirect all 1. Create a mock file ( const Swiper = jest.fn(() => null);
Swiper.use = jest.fn();
const SwiperSlide = jest.fn(() => null);
// Mocks for swiper/modules
const Navigation = {};
const Pagination = {};
const Virtual = {};
const Scrollbar = {};
const Autoplay = {};
const EffectFade = {};
module.exports = {
__esModule: true,
default: Swiper,
Swiper,
SwiperSlide,
Navigation,
Pagination,
Virtual,
Scrollbar,
Autoplay,
EffectFade,
};2. Update moduleNameMapper: {
"^swiper$": "<rootDir>/mocks/swiper.js",
"^swiper/(.*)$": "<rootDir>/mocks/swiper.js",
}This ensures that any import from |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. I am using next v11.1.2, swiper ^ 7.2.0.
Swiper works fine in the application itself, but when writing tests, Jest cannot find the component
import {Swiper, SwiperSlide} from 'swiper / react';How to solve this problem?
Beta Was this translation helpful? Give feedback.
All reactions