Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest: test suite failed to run Error: No message was provided

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);
});
like image 843
Joff Avatar asked Nov 18 '22 08:11

Joff


1 Answers

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.

like image 148
Austin Avatar answered Dec 05 '22 15:12

Austin