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 suggestions are appreciated. Thanks!
