jefflau / jest-fetch-mock

Jest mock for fetch
MIT License
886 stars 117 forks source link

Typings: add call signature compatible with original fetch #64

Closed Guria closed 6 years ago

Guria commented 6 years ago

Useful for classes that accepts fetch in constructor like:

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')
})
jefflau commented 6 years ago

Hi Guria,

I do not use typescript currently so I will page in @eryshev who did the original typescript definitions.

alexeyeryshev commented 6 years ago

Hi,

LGTM; 👍