{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/react-native/issues/20508","repository_url":"https://api.github.com/repos/facebook/react-native","labels_url":"https://api.github.com/repos/facebook/react-native/issues/20508/labels{/name}","comments_url":"https://api.github.com/repos/facebook/react-native/issues/20508/comments","events_url":"https://api.github.com/repos/facebook/react-native/issues/20508/events","html_url":"https://github.com/facebook/react-native/issues/20508","id":347091960,"node_id":"MDU6SXNzdWUzNDcwOTE5NjA=","number":20508,"title":"0.56 regression: jest.mock only works when defined in jestSetup.js, not in individual Snapshots tests","user":{"login":"farhanmannan","id":603598,"node_id":"MDQ6VXNlcjYwMzU5OA==","avatar_url":"https://avatars1.githubusercontent.com/u/603598?v=4","gravatar_id":"","url":"https://api.github.com/users/farhanmannan","html_url":"https://github.com/farhanmannan","followers_url":"https://api.github.com/users/farhanmannan/followers","following_url":"https://api.github.com/users/farhanmannan/following{/other_user}","gists_url":"https://api.github.com/users/farhanmannan/gists{/gist_id}","starred_url":"https://api.github.com/users/farhanmannan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/farhanmannan/subscriptions","organizations_url":"https://api.github.com/users/farhanmannan/orgs","repos_url":"https://api.github.com/users/farhanmannan/repos","events_url":"https://api.github.com/users/farhanmannan/events{/privacy}","received_events_url":"https://api.github.com/users/farhanmannan/received_events","type":"User","site_admin":false},"labels":[{"id":650767894,"node_id":"MDU6TGFiZWw2NTA3Njc4OTQ=","url":"https://api.github.com/repos/facebook/react-native/labels/:warning:Regression","name":":warning:Regression","color":"e99695","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-08-02T16:46:51Z","updated_at":"2018-08-03T15:55:20Z","closed_at":null,"author_association":"NONE","body":"<!-- Requirements: please go through this checklist before opening a new issue -->\r\n  - [x] Review the documentation: https://facebook.github.io/react-native\r\n  - [x] Search for existing issues: https://github.com/facebook/react-native/issues\r\n  - [x] Use the latest React Native release: https://github.com/facebook/react-native/releases\r\n\r\n## Environment\r\n```\r\nReact Native Environment Info:\r\n   System:\r\n     OS: macOS High Sierra 10.13.2\r\n     CPU: x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz\r\n     Memory: 69.35 MB / 8.00 GB\r\n     Shell: 3.2.57 - /bin/bash\r\n   Binaries:\r\n     Node: 8.11.2 - /usr/local/bin/node\r\n     Yarn: 1.7.0 - /usr/local/bin/yarn\r\n     npm: 5.6.0 - /usr/local/bin/npm\r\n     Watchman: 4.9.0 - /usr/local/bin/watchman\r\n   SDKs:\r\n     iOS SDK:\r\n       Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3\r\n     Android SDK:\r\n       Build Tools: 23.0.1, 23.0.3, 25.0.2, 25.0.3, 26.0.1, 27.0.3\r\n       API Levels: 23, 25, 26, 27\r\n   IDEs:\r\n     Android Studio: 3.1 AI-173.4819257\r\n     Xcode: 9.4/9F1027a - /usr/bin/xcodebuild\r\n   npmPackages:\r\n     react: 16.4.1 => 16.4.1\r\n     react-native: 0.56.0 => 0.56.0\r\n   npmGlobalPackages:\r\n     create-react-native-app: 1.0.0\r\n     react-native-cli: 2.0.1\r\n```\r\n\r\n## Description\r\nHi there, thanks for taking the time to read this and thanks for the many fixes in the 0.56 upgrade. Sadly I believe this is a regression. This was working fine on 0.55. I cannot afford the technical debt of not upgrading to the latest RN version as the upgrade procedure is too time-expensive.\r\n\r\nI have jest mocks (mocked functions, modules and components) in my `jestSetup.js` file (pointed to from `package.json`), and I also have mocks in individual test files, including unit tests and snapshot tests. \r\n\r\nIn my individual snapshot tests, the mocks do not work anymore - the mocks exist (I can console.log them) but when the snapshot tests are run, the mocked functions are not called - instead the \"real\" functions are called. This is NOT the case for mocks defined the SAME way but placed in `jestSetup.js` - the snapshots call the mocked functions as expected when they are defined in `jestSetup.js`.\r\n\r\nI have moved as many mocks as possible to jestSetup.js but unfortunately some tests require the functions to be unmocked (e.g. unit tests) so this cannot fix all my new errors caused by upgrading to \r\n0.56.\r\n\r\nPlease let me know if there is a workaround and if a fix is on the horizon.\r\n\r\n## Reproducible Demo\r\nExample snapshot test with mock that doesn't work unless moved into `jestSetup.js`\r\n```\r\nimport 'react-native';\r\nimport renderer from 'react-test-renderer';\r\nimport React from 'react';\r\nimport sinon from 'sinon';\r\n\r\njest.mock(\r\n  '../../src/components/common/ProfilePicture/StarredPicture/StarredPicture',\r\n  () => () => { return ''; },\r\n);\r\n\r\ntest('renders correctly', () => {\r\n  const stub = sinon.stub(console, 'error');\r\n  const tree = renderer.create(<Profile />).toJSON();\r\n  const tree = renderer\r\n    .create(<Profile />)\r\n    .toJSON();\r\n  expect(tree).toMatchSnapshot();\r\n  // call count is one to reflect one required proptypes.\r\n  expect(stub.callCount).toEqual(1); \r\n```\r\n\r\npackage.json\r\n```\r\n\"jest\": {\r\n    \"automock\": false,\r\n    \"preset\": \"react-native\",\r\n    \"setupFiles\": [\r\n      \"./src/jestSetup\",\r\n    ],\r\n    \"transform\": {\r\n      \"^.+\\\\.js$\": \"<rootDir>/node_modules/react-native/jest/preprocessor.js\"\r\n    },\r\n    \"transformIgnorePatterns\": [\r\n      \"node_modules/(?!@expo)/\"\r\n    ],\r\n    \"collectCoverageFrom\": [\r\n      \"src/**/*.js\"\r\n    ]\r\n  }\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/facebook/react-native/issues/comments/410297204","html_url":"https://github.com/facebook/react-native/issues/20508#issuecomment-410297204","issue_url":"https://api.github.com/repos/facebook/react-native/issues/20508","id":410297204,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMDI5NzIwNA==","user":{"login":"shyaniv7","id":1275647,"node_id":"MDQ6VXNlcjEyNzU2NDc=","avatar_url":"https://avatars3.githubusercontent.com/u/1275647?v=4","gravatar_id":"","url":"https://api.github.com/users/shyaniv7","html_url":"https://github.com/shyaniv7","followers_url":"https://api.github.com/users/shyaniv7/followers","following_url":"https://api.github.com/users/shyaniv7/following{/other_user}","gists_url":"https://api.github.com/users/shyaniv7/gists{/gist_id}","starred_url":"https://api.github.com/users/shyaniv7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shyaniv7/subscriptions","organizations_url":"https://api.github.com/users/shyaniv7/orgs","repos_url":"https://api.github.com/users/shyaniv7/repos","events_url":"https://api.github.com/users/shyaniv7/events{/privacy}","received_events_url":"https://api.github.com/users/shyaniv7/received_events","type":"User","site_admin":false},"created_at":"2018-08-03T15:55:19Z","updated_at":"2018-08-03T15:55:19Z","author_association":"NONE","body":"@StevenLambion according to the doc on `jest-hoist`\r\n\r\n>This plugin is automatically included when using babel-jest.\r\n\r\nsince react-native is using babel-jest im not sure how adding it would make a difference.\r\nI could be wrong here because i dont understand it very well but adding it in babelrc did not fix the issue for us"}}
{"actor":{"display_login":"shyaniv7"}}