@debuggercrafts/storybook-addon-mock-api

1.1.0 • Public • Published

Storybook Mock fetch calls Build Status

Mock fetch calls using mockFetch api.

Usage

  1. Add decorator to configure mockFetch library.
  2. Setup mocks with mockFetch api.
import mockFetch from '../../src/index'

...
storiesOf('About mocking api calls')
  .addDecorator(
    // Configure mockFetch
    mockFetch({
      fallbackToNetwork: true,
      sendAsJson: true,
      overwriteRoutes: false,
    })
  )
  .add('Fetch ',
    () => <button onClick={fetch('api/apples')}>Fetch the call</button>, 
    {
      mockFetch: mockFetch => {
        // Setup mock fetch 
        mockFetch.get('/api/apples', {
          status: 200,
          body: [1, 3, 4],
        })
      },
    }
  )

Readme

Keywords

Package Sidebar

Install

npm i @debuggercrafts/storybook-addon-mock-api

Weekly Downloads

15

Version

1.1.0

License

ISC

Unpacked Size

380 kB

Total Files

16

Last publish

Collaborators

  • rihdus