1.1.0 • Published 5 years ago

@debuggercrafts/storybook-addon-mock-api v1.1.0

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

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],
        })
      },
    }
  )