question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[0.54] BlobModule.addNetworkingHandler mock missing in jest setup

See original GitHub issue

Upgrading 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

screen shot 2018-03-08 at 12 12 31 pm

Steps to Reproduce

  • Upgrade react-native to 0.54.0
  • Run jest tests

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
n-kumaricommented, Mar 9, 2018

@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

BlobModule: {
    BLOB_URI_SCHEME: 'content',
    BLOB_URI_HOST: null,
    enableBlobSupport: jest.fn(),
    disableBlobSupport: jest.fn(),
    createFromParts: jest.fn(),
    sendBlob: jest.fn(),
    release: jest.fn(),
  },

to

BlobModule: {
    BLOB_URI_SCHEME: 'content',
    BLOB_URI_HOST: null,
    addNetworkingHandler: jest.fn(),
    enableBlobSupport: jest.fn(),
    disableBlobSupport: jest.fn(),
    createFromParts: jest.fn(),
    sendBlob: jest.fn(),
    release: jest.fn(),
  }
4reactions
n-kumaricommented, Mar 9, 2018

@hramos BlobModule .addNetworkingHandler is being used in Libraries/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

screen shot 2018-03-09 at 9 50 40 am

Let me know if this helps.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found