question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'bundleId' of undefined when running Jest tests

See original GitHub issue

Geetting the following error when running jest tests:

Error:

TypeError: Cannot read property 'bundleId' of undefined

Code:

import DeviceInfo from 'react-native-device-info'
const bundleId = DeviceInfo.getBundleId()

package.json:

"react": "~15.4.1",
"react-native": "^0.38.1"

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

63reactions
carloscuestacommented, Mar 22, 2017

Just mock the method you’re using @zhen639 @arunshan

jest.mock('react-native-device-info', () => {
  return {
    getUniqueID: jest.fn()
  }
})
2reactions
machourcommented, Feb 14, 2018

The solution provided by @carloscuesta worked for me.

package.json:

  "jest": {
    "setupFiles": [
      "./testenv.js"
    ],
    // ...

testenv.js:

jest.mock('react-native-device-info', () => {
  return {
    getModel: jest.fn(),
  };
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read properties of undefined (reading 'length') JEST ...
I am trying to implement jest tests to my project but I have error while running test. The thing is that I dont...
Read more >
cannot read properties of undefined (reading 'html') at new ...
I've setup a monorepo with Node.js and React. Trying to configure jest to run test suites the api Node works fine but I...
Read more >
Unit tests - Mattermost Developers
Review our guidelines for unit testing for your Mattermost webapp, including a guide on how to do ... TypeError: Cannot read property 'filter'...
Read more >
Jest unit test fails with Error: Uncaught [TypeError: Cannot ...
... Uncaught [TypeError: Cannot read property 'id' of undefined] - React - EJ 2. ... running this simple test with Jest on a...
Read more >
Troubleshooting - Jest
Try running Jest with --no-watchman or set the watchman configuration option to false . Also see watchman troubleshooting. Tests are Extremely ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found