I am using jest for unit testing in of nodeJS APIs. I have installed jest and added it to the script in package.json as well. But facing the issue:
FAIL api/test/math.test.js
โ Test suite failed to run
TypeError: Cannot read property 'prototype' of undefined
at module.exports (node_modules/request-promise-core/configure/request2.js:34:48)
at Object.<anonymous> (node_modules/request-promise-native/lib/rp.js:15:1)
at Object.<anonymous> (node_modules/jsdom/lib/api.js:6:17)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.091s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `jest`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Below are my sample classes for the same :
math.js :
const sum = (a, b) => a + b
const mul = (a, b) => a * b
const sub = (a, b) => a - b
const div = (a, b) => a / b
export default { sum, mul, sub, div };
math.test.js :
const {sum, mul, sub, div} = require("./math")
test("Adding 1 + 1 equals 2", () => {
expect(sum(1, 1)).toBe(2)
})
test("Multiplying 1 * 1 equals 1", () => {
expect(mul(1, 1)).toBe(1)
})
test("Subtracting 1 - 1 equals 0", () => {
expect(sub(1, 1)).toBe(0)
})
test("Dividing 1 / 1 equals 1", () => {
expect(div(1, 1)).toBe(1)
})
Any suggestiona are appreciated. Thanks!
I'm having a similar pb...
Any suggestions?
@ankita-p17 I fixed it by adding "jest": true to my .eslintrc env as suggested here. Let me know if that fixes it for you as well :)
Same problem here, I already had, not fixing it. I also realy don't understand what does that have to do with jest, running jest won't run eslint.
@ankita-p17 I fixed it by adding
"jest": trueto my.eslintrcenv as suggested here. Let me know if that fixes it for you as well :)
I do not have linting. I am with @wintercounter that why we will need eslint for Jest
I solved simply by npm i request
Most helpful comment
I solved simply by
npm i request