Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
124
rated 0 times [  129] [ 5]  / answers: 1 / hits: 19551  / 7 Years ago, mon, january 8, 2018, 12:00:00

I was trying to implement the example shown in Jest website: Getting started with Jest.



While running npm test on I was getting the following error:



FAIL  src/sum.test.js
● Test suite failed to run

TypeError: environment.setup is not a function

at node_modules/jest-runner/build/run_test.js:112:23


sum.js:



function sum(a, b){
return a+b;
}
module.exports = sum;


sum.test.js:



const sum = require('./sum');

test('adding sum function', () => {
expect(sum(234,4)).toBe(238);
})


sum.js and sum.test.js are an exact copy of the example shown in Getting started with Jest.



package.json:



{
name: jest-demo-test,
version: 0.1.0,
private: true,
dependencies: {
react: ^16.2.0,
react-dom: ^16.2.0,
react-scripts: 1.0.17
},
scripts: {
start: react-scripts start,
build: react-scripts build,
test: jest,
eject: react-scripts eject
},
devDependencies: {
jest: ^22.0.4
}
}


So, how can I get rid of TypeError: environment.setup is not a function error?


More From » reactjs

 Answers
8

Jest is included with react-scripts. The error is due to a conflict that arose when you installed Jest in a project started with react-scripts. The Getting started with Jest guide expects a 'clean' project.



Simply remove Jest from your (dev)dependencies and it should work.



If you want to use Jest for testing React components (which you probably do), you need to modify your test script in package.json to react-scripts test --env=jsdom, as it was.


[#55516] Thursday, January 4, 2018, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jenamackennac

Total Points: 304
Total Questions: 110
Total Answers: 107

Location: Ecuador
Member since Thu, Jun 4, 2020
4 Years ago
jenamackennac questions
Fri, Feb 18, 22, 00:00, 2 Years ago
Wed, Apr 21, 21, 00:00, 3 Years ago
Thu, Apr 1, 21, 00:00, 3 Years ago
Tue, Feb 2, 21, 00:00, 3 Years ago
;