Skip to content

Instantly share code, notes, and snippets.

@alenia
Last active May 23, 2017 18:05
Show Gist options
  • Save alenia/e1128775487e8a3fafd134496ba01c89 to your computer and use it in GitHub Desktop.
Save alenia/e1128775487e8a3fafd134496ba01c89 to your computer and use it in GitHub Desktop.
const mockRootNavigator1 = function() {
return {
router: {
getComponentForState: jest.fn
}
}
}
function mockRootNavigator2() {
return {
router: {
getComponentForState: jest.fn
}
}
}
const mockRootNavigator3 = () => {
return {
router: {
getComponentForState: jest.fn
}
}
}
//jest.mock('../../navigators/root_navigator', () => { //if I uncomment this it'll work
//return {
//router: {
//getComponentForState: jest.fn
//}
//}
//})
jest.mock('../../navigators/root_navigator', mockRootNavigator1) // this will fail
//jest.mock('../../navigators/root_navigator', mockRootNavigator2) // this will fail
//jest.mock('../../navigators/root_navigator', mockRootNavigator3) // this will fail
@alenia
Copy link
Author

alenia commented May 23, 2017

Here's my test error:

● Test suite failed to run

    /Users/dwellisz/p/react-mobile/src/actions/__tests__/navigation_test.js: babel-plugin-jest-hoist: The second argument of `jest.mock` must be a function.

@alenia
Copy link
Author

alenia commented May 23, 2017

If I use lines 8-14 instead of line 15 it works

@alenia
Copy link
Author

alenia commented May 23, 2017

As far as I can tell the only difference is a named function vs an anonymous function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment