jefflau / jest-fetch-mock

Jest mock for fetch
MIT License
883 stars 116 forks source link

Allow using HTTP method as a predicate #142

Closed sandinmyjoints closed 4 years ago

sandinmyjoints commented 4 years ago

The various mock-if conditionals take the url as input, but it'd be great to have a way to choose whether to mock or not based on HTTP method, for example, only mock POSTs.

jefflau commented 4 years ago

Is this possible to do @yinzara?

yinzara commented 4 years ago

Absolutely. They also accept a function that accepts a http.Request and returns a boolean of true or false.

fetch.doMockIf(req => req.method === "POST")

jefflau commented 4 years ago

Maybe we can add this as an example!

yinzara commented 4 years ago

It already is. See Readme.md in the "Functions" section :)