My current setup involves using jest
for testing my typescript
codes.
import ClassA from '../classA';
jest.mock('../classA');
However, when I try to import
a class
from my classA.ts
file, an error is thrown by jest
:
export default ClassA;
^^^^^^
SyntaxError: Unexpected token export
This issue arises despite having the following jest
configuration in my package.json
:
"devDependencies": {
"@types/jest": "^19.2.3",
"jest": "^20.0.4",
"ts-jest": "^20.0.4",
"ts-node": "^3.0.2",
"typescript": "^2.3.2"
},
"jest": {
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
]
}