I am testing some React components and using Jest I found an unexpected problem for import 'react-extras'. I tried to solve using transformIgnorePatterns in my Jest config file, but it didn't solve the problem.
I've seen related issues but none of them ended up helping me.
Note: react-extras is exported as module
Related issues:
Jest output:
Details:
C:\Users\allan\teste-tecnico-brainn\node_modules\react-extras\dist\index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export { default as autoBind
} from 'auto-bind/react';
SyntaxError: Unexpected token 'export'
1 | import { ChangeEvent, useContext, useEffect, useState } from 'react'
> 2 | import { For } from 'react-extras'
| ^
My Jest config file (as JSON):
{
"moduleNameMapper": {
"~/(.*)": "<rootDir>/src/$1"
},
"transformIgnorePatterns": [
"/node_modules/(?!(react-extras)/)"
],
"setupFilesAfterEnv": [
"@testing-library/jest-dom/extend-expect"
],
"testMatch": [
"**/?(*.)spec.ts?(x)",
"**/?(*.)test.ts?(x)"
],
"globals": {
"ts-jest": {
"tsconfig": "tsconfig.json",
"diagnostics": false
}
},
"testEnvironment": "jsdom",
"preset": "ts-jest"
}
You can see my repository clicking here.