Skip to content

Conditional Mocking, Request Based Responses, Enable/Disable Facade, and Abort Mocking

Latest
Compare
Choose a tag to compare
@jefflau jefflau released this 18 Dec 07:03
· 58 commits to master since this release
a0a22de

Fetches can now be mocked conditionally based upon URL or request matching. This gives the developer the capability to allow some requests to use the real fetch implementation and others to be mocked. See the Readme for detailed usage information.

The async functionality added with the last release has been enhanced. The async function that can be used to return a dynamic response now accepts an optional single API argument of "request" of type Request that can be used to vary the response returned from the mock fetch.

Enabling and disabling jest-fetch-mock can now be handled via the "enableMocks/disableMocks" exported functions instead of relying on custom code.

Request aborting is now supported by the mock framework. Both forced aborting via "mockAbort()" or "mockAbortOnce()" or aborting dynamically by passing a "signal" option to the "fetch" function and calling "abort" on the controller.

Thank you @yinzara for leading this one.

Merry Christmas all!

Jeff