Skip to content

Jest testing problem: Invariant Violation: Native module cannot be null. #1679

@KamWis

Description

@KamWis

Version

Tell us which versions you are using:

  • react-native-router-flux v3.38.0
  • react-native v0.42.0
  • jest 19.0.2

Expected behaviour

Test suite should NOT fail to run

Actual behaviour

Test suite failed to run

    Invariant Violation: Native module cannot be null.

      at invariant (node_modules/fbjs/lib/invariant.js:44:15)
      at Linking.NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:32:1)
      at new Linking (node_modules/react-native/Libraries/Linking/Linking.js:119:141)
      at Object.<anonymous> (node_modules/react-native/Libraries/Linking/Linking.js:191:16)
      at Object.get Linking [as Linking] (node_modules/react-native/Libraries/react-native/react-native.js:90:22)
      at Object.<anonymous> (node_modules/react-native-experimental-navigation/NavigationRootContainer.js:15:36)

Explicit line breaking test: import { Actions } from 'react-native-router-flux' (when deleted and replaced with arrow function - doesn't happen:
<TouchableNativeFeedback onPress={Actions.SecondScene}>
into
<TouchableNativeFeedback onPress={() => {}}>

Test itself:

import 'react-native'
import React from 'react'
import FirstScene from '../index'

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer'

it('renders correctly', () => {
  const tree = renderer.create(
    <FirstScene />
  )

  expect(tree).toBeDefined()
})

Steps to reproduce

  1. Create standard react-native component,
  2. Import Actions,
  3. run jest or npm run test

Thank you for awesome library :) Reporting this issue because I care about growth and well-being of it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions