0
votes

I'm trying to make jest/enzyme tests in react

I have this test:

import React from 'react';

import { shallow } from 'enzyme';
import { mount } from 'enzyme'

import WorkOutForm from './workOutForm';

describe('WorkOutForm', () => {
      it('should start a new workoutForm with empty state', () => {
        const component = mount(<WorkOutForm/>)

        expect(component).toMatchSnapshot();
      });
   })

but when i do a npm run test i receive:

src/workout/workOut.test.js ● Test suite failed to run

babel-jest: Babel ignores src/workout/workOutForm.jsx - make sure to include the file in Jest's transformIgnorePatterns as well.

I try to add this file in the package.json:

  "jest": {
    "transformIgnorePatterns": [
      "src/workout/workOutForm.jsx"
    ]
  }

but i'm receiving the same error. where i have to put this?

2

2 Answers

0
votes

where i have to put this?

You should not ignore jsx source files. What you need to do is convert your jsx to js using babel.

You need to use babel-preset-react. This will automatically add @babel/plugin-transform-react-jsx for the transformation.

Then put this in your .babelrc

{
  "presets": ["@babel/preset-react"]
}
0
votes

I have already this error and i fixed changing the code from:

"ignore": [
   "./test",
   "./src/assets",
   "./src/stories",
   "./src/.storybook"
]

To this:

"ignore": [
   "./src/assets",
   "./src/stories",
   "./src/.storybook"
]

I remove my test folder from the .babelrc ignore prop and its works for me!