Jest encountered an unexpected token - SyntaxError: Unexpected token 'export'
react-markdown
is shipped as js, add babel-jest
as a transformer in your jest config
transform: {
'^.+\\.ts?$': 'ts-jest',
"^.+\\.(js|jsx)$": "babel-jest"
},
Jest encountered an unexpected token when working with React TypeScript
Looks like your test file is a js
file (src\__tests__\DatePicker.spec.js
) instead of ts?x
file which means this pattern will never meet "^.+\\.(ts|tsx)$": "ts-jest"
.
However, you might know tsc
can also have capability to transpile your js code as well as long as you set allowJs: true
as you already did. So I think your problem would be fixed as you refine your pattern to to transform above including jsx
file:
{
transform: {
"^.+\\.(t|j)sx?$": "ts-jest",
}
}
Jest encountered an unexpected token + react markdown
In the jest.config
file, you need to add the following to the moduleNameMapper
attribute:
"react-markdown": "<rootDir>/node_modules/react-markdown/react-markdown.min.js"
So effectively, your moduleNameMapper
should really look like this:
...
moduleNameMapper: {
'next/router': '<rootDir>/__mocks__/next/router.js',
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
'^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$': '<rootDir>/__mocks__/file-mock.js',
'react-markdown': '<rootDir>/node_modules/react-markdown/react-markdown.min.js',
},
...
Good luck!
Related Topics
Expected Linebreaks to Be 'Lf' But Found 'Crlf' Linebreak-Style
Mongodb Get Data to Display in HTML
React Native: Image Not Displaying With Dynamic/Local Uri
Ios Safari/Chrome - Unwanted Scrolling When Focusing an Input Inside the Modal
How to Set Top and Bottom Margin in Addhtml
Charts.Js Graph Not Scaling to Canvas Size
React-Router Go Back a Page How to Configure History
Make the Bootstrap Table Scroll-Able Vertically and Horizontally With Fixed Header
How to Scroll Left or Right Inside a Div Using Pure JavaScript Function and No Jquery
Check Whether a String Contains Only Special Characters
Make Discord Bot Send Picture With Message With Nodejs
Reactjs: Expected Onclick Listener to Be a Function, Instead Got Type String
Get Docx File Contents Using Javascript/Jquery
How to Change Font-Size in Vuetify Component
How to Remove Time from Datetime in SQL
Jquery Do Not Allow Alphabets to Be Entered in Input Field
Can We Cast a Generic Object to a Custom Object Type in JavaScript