[0.54] BlobModule.addNetworkingHandler mock missing in jest setup
See original GitHub issueUpgrading react native to 0.54.0 causes the jest tests to fail with an error
TypeError: BlobModule.addNetworkingHandler is not a function
Environment:
OS: macOS Sierra 10.12.6 Node: 8.9.1 Yarn: 1.3.2 npm: 5.6.0 Watchman: 4.7.0 Xcode: Xcode 9.0 Build version 9A235 Android Studio: Not Found
Packages: (wanted => installed) react: ^16.3.0-alpha.1 => 16.3.0-alpha.1 react-native: 0.54.0 => 0.54.0
Expected Behavior
The tests should not break on upgrade
Actual Behavior
The test suite fails to run with an error

Steps to Reproduce
- Upgrade react-native to 0.54.0
- Run jest tests
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Cannot mock a module with jest, and test function calls
The problem. The reason you're getting that error has to do with how various operations are hoisted. Even though in your original code...
Read more >Configuring Jest
Node modules are automatically mocked when you have a manual mock in place (e.g.: __mocks__/lodash. js ).
Read more >Testing with Jest - React Navigation
Testing with Jest. Testing code using React Navigation may require some setup since we need to mock native dependencies used in the navigators....
Read more >Using Mock Service Worker to Improve Jest Unit Tests - WWT
Unfortunately, due to mocking tasks-service our test will no longer trigger calls to either of those modules. Our test has lost the ability...
Read more >Testing with Jest - React Navigation - Netlify
Testing code using React Navigation takes some setup since we need to mock some native dependencies used in the navigators.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@FireNoid I think the change should be made in the jest setup file instead of the file
node_modules/react-native/Libraries/Blob/BlobManager.js
itself.The setup file is where we should mock the required modules. So, in node_modules/react-native/jest/setup.js
Change
to
@hramos
BlobModule .addNetworkingHandler
is being used inLibraries/Network/XMLHttpRequest.js
but probably does not have a test coverage around it. Our test suites are designed differently than the ones being used by react-native, so not sure which test suite it is.Here is the what the failure says
Let me know if this helps.