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

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"

4 thoughts on “TypeError: Cannot read property ‘bundleId’ of undefined when running Jest tests

  1. terminate the packager by exiting the terminal window

    then

    manually start with:

    $ react-native start
    

    I hope this helps somehow!

  2. If someone else runs into this error, try creating a folder named __mocks__ in the same folder
    as node_modules then add a file named react-native-device-info.js in the folder you just created, with contents:

    module.exports = {
      getBundleId: jest.genMockFunction(),
      // add more methods as needed
    };
    
  3. 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(),
      };
    });
    

Comments are closed.

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

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"

2 thoughts on “TypeError: Cannot read property ‘bundleId’ of undefined when running Jest tests

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

    jest.mock('react-native-device-info', () => {
      return {
        getUniqueID: jest.fn()
      }
    })
    

Comments are closed.