Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm using react with typecript and after adding swiper dependecy my tests start to fail.
These are my configuration:
jest.config.js:
import type { Config } from '@jest/types';
const config: Config.InitialOptions = {
verbose: true,
transform: {
'^.+\\.ts?$': 'ts-jest',
transformIgnorePatterns: ['node_modules/(?!swiper|ssr-window|dom7/)'],
export default config;
babel.config.js:
module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-flow'],
plugins: [
'babel-plugin-styled-components',
'@babel/plugin-proposal-class-properties',
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/__mocks__/fileMock.js',
'\\.(css|less)$': '<rootDir>/__mocks__/styleMock.js',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
transform: {
'^.+\\.ts?$': 'ts-jest',
'^.+\\.(js|jsx)$': 'babel-jest',
package.json:
"jest": {
"moduleNameMapper": {
"swiper/react": "swiper/react/swiper-react.js",
"swiper/css": "swiper/swiper.min.css"
"transform": {
"^.+\\.css$": "jest-transform-css"
"transformIgnorePatterns": "node_modules/(?!(swiper|ssr-window|dom7)/)",
–
I actually had the same issue with swiper and these lines in jest.config.js solved it:
transformIgnorePatterns: ['/node_modules/(?!swiper|ssr-window|dom7)'],
moduleNameMapper: {
'swiper/react': ['<rootDir>/node_modules/swiper/react/swiper-react.js'],
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.