Unable to intercept React Native Image source URI requests in Jest tests
See original GitHub issueI’m trying to use msw in Jest tests (so, Node) to intercept React Native’s Image
component network requests. I have no need to leverage msw in RN itself at this time, so this should pertain purely to Node integration (as I understand it). I messed around with various uses of react-native-url-polyfill
and node-fetch
to no avail, but they are not currently utilized in the reproduction below.
Environment
Name | Version |
---|---|
msw | 0.24.2 |
node | 14.15.1 |
OS | Windows 10 and macOS Big Sur |
Request handlers
import { setupServer } from 'msw/node'
import { rest } from 'msw'
const server = setupServer(
rest.get('anything-other-than-source-uri-provided-to-image', () => {...})
)
server.listen({ onUnhandledRequest: 'error' })
Actual request
<Image source={{ uri: 'https://some-unhandled-uri' }} />
Current behavior
Test renders the component without errors.
Expected behavior
Expected msw to throw as there is no handler defined for the source URI provided, and onUnhandledRequest
is set to 'error'
.
Full Reproduction
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Jest+React Native Testing Library: How to test an image src?
It's a little hard to say because we can't see <ImageBackground> component or what it does ...
Read more >How to mock API calls in React Native - DEV Community
At interception, it generates random data mocking the API. We'll run our tests in Node.js with Jest. We use React Native Testing Library...
Read more >Testing your React App with Puppeteer and Jest | by Rajat S
Go to src/App and create a new file called App.test.js . ... successful requests, and also intercept the request and force the failure...
Read more >Testing React Native Todo Application Using Cypress
IntroductionRecently I have read a nice guide to writing unit and integration tests using Jest for a React Native Todo app.
Read more >React Native WebView: A complete guide - LogRocket Blog
Creating the basic URL structure; Writing the basic inline HTML; Communicating between JavaScript and Native; The injectJavaScript method. Below ...
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 FreeTop 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
Top GitHub Comments
I have tried also with
DEBUG=*
but I don’t see any log from interceptors. I only see about patchingPer @marcosvega91:
It doesn’t seem we can tackle this on the library’s side. If anybody finds out more details, please comment here. Thanks.