Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
react-network-hijack
Advanced tools
A small higher order component for hijacking all network requests while a component is mounted
The aim for this library is to provide an easy way to mock network requests in a browser while using React components. This was originally developed with the intent of being used as part of your stories in Storybook but there is no reason it shouldn't work with a framework which runs in the browser.
To use this in your stories or other browser tests you can specify a set of urls, their methods to mock and what data to return as options to the HoC and then pass your own component in.
import withNetworkMock from "react-network-hijack";
const NetworkMocked = withNetworkMock({
GET: {
"https://jsonplaceholder.typicode.com/todos/1": {
body: {
...
},
status: 200,
delay: 200
}
},
POST: {
...
}
})(MyComponent);
The top level object contains the methods to mock. For each of these methods you can mock individual urls with a set of options.
body:
status:
delay:
If a request is not mocked an event will be emitted that you can capture in some other component and display a warning to the user. You can import this with:
import { UNMOCKED_EVENT } from "react-network-hijack";
You can also pass a whitelist to the withNetworkMock
function to stop emits happening on certain URLs. The whitelist can contain either regular expressions for fuzzy matching or strings for exact matches.
import withNetworkMock from "react-network-hijack";
const whitelist = ["example.com", /www.example.com/];
const NetworkMocked = withNetworkMock(config, whitelist)(MyComponent);
This project is licensed under the MIT License - see the LICENSE.md file for details
FAQs
A small higher order component for hijacking all network requests while a component is mounted
We found that react-network-hijack demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.