React-native-i18n: TypeError: Cannot read property 'prototype' of undefined + Jest + NodeJS

Created on 27 Nov 2018  ยท  6Comments  ยท  Source: AlexanderZaytsev/react-native-i18n

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!

Most helpful comment

I solved simply by npm i request

All 6 comments

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": true to my .eslintrc env 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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tonygentilcore picture tonygentilcore  ยท  4Comments

xilonxiao picture xilonxiao  ยท  5Comments

sibelius picture sibelius  ยท  4Comments

wyzzy picture wyzzy  ยท  5Comments

mphasize picture mphasize  ยท  7Comments