score:20
Accepted answer
Ok after I added this @babel/preset-typescript
into my presets, that error went away:
"test": {
"presets": [
"@babel/preset-typescript", // <---
[
"next/babel",
{
"preset-env": {
"modules": "commonjs"
}
}
]
],
"plugins": [
[
"styled-components",
{
"ssr": true,
"displayName": true
}
]
]
}
score:-2
your const declarion does not have a variable name. const variableName: Type = new Type() or const variableName: Type; or const variableName = new Type;
score:0
In case just having the @babel/typescript
preset does not work.
You could try the following:
- Rename the failing test file to either
.ts
or.tsx
depending on whether you have JSX in your test (in this caseAstronaut.test.tsx
) - Update your jest config docs (in this case package.json), add
"moduleFileExtensions": [
"js",
"ts",
"tsx"
],
Source: stackoverflow.com
Related Query
- Jest test on typescript file syntax error: "interface is a reserved word in strict mode"
- Syntax Error when test component with SASS file imported
- jest with typescript throws an error when importing a file
- Jest Snapshot test returns an error looking for the file with a .ts extension though the test file is a .tsx
- React with TypeScript + Jest + Enzyme -- Error Test Expected 1 arguments, but got 2
- Await is a reserved word error inside async function
- React.js - Syntax error: this is a reserved word in render() function
- jest updateSnapshot for specific test file
- Testing with Jest failed with Error: Error watching file for changes: EMFILE
- Jest test passes but error not caught and logs to console
- React jest test with enzyme error
- Specify window.location for each test file for Jest
- React Jest test fails to run with ts-jest - Unexpected token on imported file
- Unable to test post methods with Jest due to error can not read mockImplementation of undefined
- Why is jest looking for a test file that no longer exists?
- Syntax error when using SVGR with Webpack and configured to output TypeScript
- React Jest test fails to run with ts-jest - Encountered an unexpected token on imported file
- use babel-jest for jest but still get syntax error
- moment-timezone.js – Getting Error When Running in Jest Test
- React / Enzyme: Invariant Violation error when running Jest / Enzyme test
- How can I make Jest test for a thrown error silently
- Jest - one function mocks file for multiple test files
- Error when running jest on a react native + typescript app (Jest encountered an unexpected token)
- Error when trying to run a test file on React component
- Typescript test with Jest with Enzyme does not recognise components
- Jest test for a copy to clipboard method using react with typescript
- ReferenceError: window is not defined. I got this error when I run npm test to unit testing by jest
- How to test with jest and typescript with types a basic react function component
- Testing Typescript Interface with Jest
- Loading a test .env file in jest
More Query from same tag
- Material UI date picker behaving differently on mobile device
- Adding a link to a key press event
- Facebook React.js Example error?
- React Higher Order Components: Proper way to add instance methods
- Dynamic routing in Next Js return 404 and then reloads
- Problem using map method with react (posts.map is not a function)
- How to customize Autocomplete tag - Material UI
- "Uncaught TypeError: fs.writeFile is not a function" when using Electron with React
- mapStateToProps returning undefined state from reducer
- How to use fixed urls for images wit PNP Carousel Control for SPFx
- How to create a vertical divider in css?
- How can I fix 'TypeError: undefined is not an object'?
- How to copy some data from one container to another container by docker-compose.yml
- How to use CellMeasurer in react-virtualized Table?
- Lagging input in ReactJS for large json structures
- Migrate a React class component to a Function component (React-google-maps)
- How to update state inside an addListener React Class Component
- Customize existing component with fixed css classes in React
- React Components are not refreshing when the prop data is changed
- How to prepending before icon for text area for React component
- re render wipes my inputs, how do I keep them?
- working with react components REACTjs
- Two onClick functions on a react component, doesn't fire up
- Why can't I push values in my state array in react.js?
- How to fix type warning for radius settings in React app
- Conditionally showing a placeholder when there is no value in the data ( ReactJS)
- ReactJS - JSON objects in arrays
- React: how can I process the data I get from an API before I render it out?
- how to manage simultaneous DOM modification
- Why does setTimeout return a number instead of text? ReactJS