npm.io
1.1.0 • Published 7 years ago

@debuggercrafts/storybook-addon-mock-api

Licence
ISC
Version
1.1.0
Deps
0
Size
371 kB
Vulns
0
Weekly
0

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

Keywords