I am converting existing tests to use typescript with ts-jest and I have everything finding all the files but all of the tests fail with the error
FAIL src/components/Buttons/__tests__/index.tsx
● Test suite failed to run
Error: No message was provided
I have no idea what is going on and I can't seem to find anyone who had the same problem by Googling either, which is scary...
package.json with jest config
"jest": {
"globals": {
"ts-jest": {
"tsConfigFile": "<rootDir>/tsconfig.json",
"babelConfig": {
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
}
},
"setupTestFrameworkScriptFile": "<rootDir>/src/setupTests.ts",
"verbose": true,
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"typeface-roboto|\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
},
"moduleFileExtensions": [
"ts", "tsx", "js", "jsx", "json", "node"
]
},
example test file...
import React from 'react';
import { shallow } from 'enzyme';
import Account from '../account';
it('renders without crashing', () => {
expect(shallow(<Account />)).toBe(1);
});
I found that adding a tsconfig.json file in my project directory fixed this issue.
My tsconfig.json file didn't need anything special in fact it didn't need anything at all! Simply having a blank tsconfig.json file allowed my tests to run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With