Closed Guria closed 6 years ago
Useful for classes that accepts fetch in constructor like:
fetch
class MyAjax { constructor(private fetch: Window['fetch']) {} get(/* ... */) { return this.fetch(/* ... */) } /* ... */ }
then in tests:
import MyAjax from './ajax' import fetch from 'jest-fetch-mock' test('', () => { fetch.mockResponseOnce(JSON.stringify({ data: '12345' })) const ajax = new MyAjax(fetch) ajax.get('/foo') })
Hi Guria,
I do not use typescript currently so I will page in @eryshev who did the original typescript definitions.
Hi,
LGTM; 👍
Useful for classes that accepts
fetch
in constructor like:then in tests: