1.0.2 • Published 3 years ago

@paprika/mock-endpoints v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

Usage

A helper function that wraps of the 'fetch-mock' library, making it easy to mock API calls from your component.

See the stories for a working examples.

  import mockEndpoints from "@paprika/mock-endpoints";

  const endpoints = [
    {
      url: '/users',
      response: [{ id: 1, name: "nahum", ... }, { id: 2, name: "jamie"}],
    },
    {
      url: '/groups',
      response: [{ id: 1, name: "UX", members: [1,2] }, {}],
    }
  ];

  export default function UserLookupStory() {
    const { endpointsAreMocked } = useMockEndpoints(endpoints);
    if (!endpointsAreMocked) return null;

    // Any API calls in this component will be intercepted and the response will come from the corresponding "response" value above
    return <UserLookup />;
  }
1.0.2

3 years ago

1.0.2-next.0

3 years ago

1.0.1

4 years ago

1.0.1-next.0

4 years ago

1.0.0

4 years ago

0.1.1-alpha.1

4 years ago

0.1.1-alpha.0

4 years ago