Site-kit-wp: Use fetch-mock-jest over jest-fetch-mock

Created on 1 May 2020  Â·  3Comments  Â·  Source: google/site-kit-wp

Feature Description

We currently use jest-fetch-mock for all of our mocking of window.fetch requests in our jest tests, but after chatting, @aaemnnosttv and I have been finding that libraries functionality and jest-matchers to be a bit lacking. Especially when it comes to checking for request body/param values, the newer fetch-mock-jest has better matchers and a nicer, more flexible API. It also better integrates with fetch-mock, which we're already using in Storybook.

This library was quite new and not well-advertised when we started, but seems well-supported now and we should try to:

  1. add the library and use it going forward for our fetch tests
  2. migrate existing tests and remove jest-fetch-mock.

_Do not alter or remove anything below. The following sections will be managed by moderators only._

Acceptance criteria

  • fetch-mock-jest is added to package.json and existing tests are migrated to use it over our existing jest-fetch-mock tests.
  • jest-fetch-mock is removed from package.json (optional; only do if we can entirely replace the other mock library)

Implementation Brief

If we can't remove jest-fetch-mock but can use both and that gives us better flexibility: let's go for that.

QA Brief

Changelog entry

  • N/A
Good First Issue P2 Eng Enhancement

Most helpful comment

I just stumbled across this. Since writing fetch-mock-jest I've found various teething problems which are - I hope - now all resolved. Thought I'd just say hello and let you know I'd be very interested to hear of any feedback you have from migrating. Let me know if anything's buggy and I will try to resolve ASAP.

All 3 comments

I just stumbled across this. Since writing fetch-mock-jest I've found various teething problems which are - I hope - now all resolved. Thought I'd just say hello and let you know I'd be very interested to hear of any feedback you have from migrating. Let me know if anything's buggy and I will try to resolve ASAP.

That sounds good to me, it technically feels like a better alternative. Regarding maintenance, fetch-mock-jest is currently a lot less popular and this could have long-term implications, but since it's new and growing, and since you @wheresrhys already checked in here (thanks!), let's give it a shot! 🎉

IB ✅

QA :heavy_check_mark:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Loganson picture Loganson  Â·  5Comments

aaemnnosttv picture aaemnnosttv  Â·  3Comments

aaemnnosttv picture aaemnnosttv  Â·  5Comments

aaemnnosttv picture aaemnnosttv  Â·  3Comments

felixarntz picture felixarntz  Â·  4Comments