ex-navigation icon indicating copy to clipboard operation
ex-navigation copied to clipboard

Trouble with jest and snapshot tests / mocking

Open Dashue opened this issue 8 years ago • 2 comments

Hitting this error.

TypeError: Cannot read property 'pushListener' of undefined

  at ExNavigationAndroidBackButtonBehavior.enable (node_modules\@exponent\ex-navigation\src\ExNavigationAndroidBackButtonBehavior.js:55:14)
  at ExNavigationAndroidBackButtonBehavior.componentDidMount (node_modules\@exponent\ex-navigation\src\ExNavigationAndroidBackButtonBehavior.js:29:6)
  at node_modules\react-test-renderer\lib\ReactCompositeComponent.js:265:25
  at measureLifeCyclePerf (node_modules\react-test-renderer\lib\ReactCompositeComponent.js:75:12)
  at node_modules\react-test-renderer\lib\ReactCompositeComponent.js:264:11
  at CallbackQueue.notifyAll (node_modules\react-test-renderer\lib\CallbackQueue.js:76:22)
  at ReactTestReconcileTransaction.close (node_modules\react-test-renderer\lib\ReactTestReconcileTransaction.js:36:26)
  at ReactTestReconcileTransaction.closeAll (node_modules\react-test-renderer\lib\Transaction.js:206:25)
  at ReactTestReconcileTransaction.perform (node_modules\react-test-renderer\lib\Transaction.js:153:16)
  at batchedMountComponentIntoNode (node_modules\react-test-renderer\lib\ReactTestMount.js:69:27)

So far I have this in my test

jest.mock("bugsnag-react-native", () => 'BugSnag')
jest.mock('react-native-intercom', () => 'Intercom')
jest.genMockFromModule('@exponent/ex-navigation')

import 'react-native';
import React from 'react';
import LoginScreen from '../../app/Screens/loginScreen';

import renderer from 'react-test-renderer';

test('renders correctly', () => {
  const tree = renderer.create(
    <LoginScreen />
  ).toJSON();
  expect(tree).toMatchSnapshot();
});

And this in my package.config

"jest": {
    "preset": "jest-expo",
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-clone-referenced-element|bugsnag-react-native|expo|@expo/*|exponent|@exponent/*)"
    ],

Thanks for any input!

Dashue avatar Mar 08 '17 12:03 Dashue

@Dashue any progress on this?

sibelius avatar May 24 '17 18:05 sibelius

Nope, gave up.

Dashue avatar May 24 '17 18:05 Dashue