Skip to content
This repository has been archived by the owner on Feb 15, 2019. It is now read-only.

Trouble with jest and snapshot tests / mocking #425

Open
Dashue opened this issue Mar 8, 2017 · 2 comments
Open

Trouble with jest and snapshot tests / mocking #425

Dashue opened this issue Mar 8, 2017 · 2 comments

Comments

@Dashue
Copy link

Dashue commented Mar 8, 2017

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!

@sibelius
Copy link
Contributor

@Dashue any progress on this?

@Dashue
Copy link
Author

Dashue commented May 24, 2017

Nope, gave up.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants