Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
@nathancahill/storybook-addon-mock
Advanced tools
This addon allows you to mock fetch or xmlhttprequest requests in storybook. If your component depends on backend apis, and your backend apis are not ready yet to feed your component, then this addon provides mock apis to build your component.
There are few packages those help the developers to mock the backend apis while building components. But those packages aren't integrated properly in storybook and also there's no scope to play with those apis in the storybook. storybook-addon-mock
provides a dedicated panel in the storybook which helps the developer to view and update the apis with multiple scenarios.
Install the addon in your project as dev dependencies.
yarn add -D storybook-addon-mock
Add the decorator in your addons, in .storybook/main.js
:
module.exports = {
addons: [
'storybook-addon-mock/register',
],
}
Add decorator in the stories.
import React from 'react'
import withMock from 'storybook-addon-mock'
import Component from './Component'
export default {
title: 'Component',
component: Component,
decorators: [withMock],
}
const Template = args => <Component {...args} />
export const Default = Template.bind({})
Default.parameters = {
mockData: [{
url: 'https://jsonplaceholder.typicode.com/todos/1',
method: 'GET',
status: 200,
response: {
data: 'This is a Mock Response!',
},
}],
}
Thanks to shilman for this solution
Add the register in your .storybook/addons.js
file
import 'storybook-addon-mock/register';
Add withMock
as a decorator in the stories.
import React from 'react';
import withMock from 'storybook-addon-mock';
storiesOf('Storybook Addon Mock', module)
.addDecorator(withMock)
.add('Getting Mock API Response', () => <ComponentWithAPICall />, {
mockData: [{
url: 'https://jsonplaceholder.typicode.com/todos/1',
method: 'GET',
status: 200,
response: {
data: 'This is a Mock Response!',
},
}],
});
MIT Licensed. Copyright (c) Farhad Yasir.
FAQs
A storybook addon to mock http request
We found that @nathancahill/storybook-addon-mock 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
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.