Using jest in my react app, describe is not defined

ReactjsJestjsEslintEslintrc

Reactjs Problem Overview


I am new to jest and trying to figure out some basic stuff in my following code

import * as actions from './IncrementalSearchActions';

describe('Incremental Search Actions', () => {
    it('Should create an incremental search action')
});

The questions/confusions I have around this are

  1. I get an error saying describe is not defined, how do I import the reuqired module?
  2. Is this supposed to be used with Karma/Jasmine?

Reactjs Solutions


Solution 1 - Reactjs

I believe the answer here is the answer to your question.

TL;DR;:

add the following to your .eslintrc file:

"env": {
    "jest": true
}

Solution 2 - Reactjs

Are your test files under a the "test" folder? make sure jest is install properly and listed on your package.json and under scripts have:

"test": "jest --coverage",

you can run the script with npm test

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiontmp devView Question on Stackoverflow
Solution 1 - ReactjsSunshinyDoyleView Answer on Stackoverflow
Solution 2 - ReactjsJulito SanchisView Answer on Stackoverflow