hrsh7th / fetch-spy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fetch-spy

simple fetch mocking module.

Usage

import * as FetchSpy from 'fetch-spy';

describe('test', () => {
  beforeEach(() => {
    FetchSpy.reset()
  })

  it('should work' () => {
    const spy = FetchSpy.spy({ method: 'GET', pathname: '/foo/bar/*' }, new Response(JSON.stringify({
      foo: 'bar'
    }), { status: 200 }));
    await complexFunction();
    expect(spy.calls).toMatchSnapshot([{
      url: '/foo/bar'
    }]);
  })
})

About


Languages

Language:TypeScript 100.0%