From 4cee629b36cd618d6d5b1061c15e48aab7047969 Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Sat, 20 Jul 2024 20:41:48 +0100 Subject: [PATCH] feat!: renamed functionMatcher to func --- docs/docs/@fetch-mock/core/route/matcher.md | 2 +- packages/core/src/Matchers.js | 4 ++-- packages/core/src/Route.js | 4 ++-- packages/core/src/__tests__/Matchers/function.test.js | 2 +- .../core/src/__tests__/Matchers/route-config-object.test.js | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/docs/@fetch-mock/core/route/matcher.md b/docs/docs/@fetch-mock/core/route/matcher.md index 8a4fc331..b9b1a7fc 100644 --- a/docs/docs/@fetch-mock/core/route/matcher.md +++ b/docs/docs/@fetch-mock/core/route/matcher.md @@ -141,7 +141,7 @@ This option can also be [set in the global configuration](/fetch-mock/docs/@fetc For use cases not covered by all the built in matchers, a custom function can be used. It should return `true` to indicate a route should respond to a request. It will be passed the `url` and `options` `fetch` was called with. If `fetch` was called with a `Request` instance, it will be passed `url` and `options` inferred from the `Request` instance, with the original `Request` available as a third argument. -As well as being passed as a standalone argument, it can also be added to the matcher object as the property `{functionMatcher: ...}` when combining with other matchers or options. +As well as being passed as a standalone argument, it can also be added to the matcher object as the property `{func: ...}` when combining with other matchers or options. ### Examples diff --git a/packages/core/src/Matchers.js b/packages/core/src/Matchers.js index 445bde6e..c24ba2f7 100644 --- a/packages/core/src/Matchers.js +++ b/packages/core/src/Matchers.js @@ -196,7 +196,7 @@ const getFullUrlMatcher = (route, matcherUrl, query) => { /** * @type {MatcherGenerator} */ -const getFunctionMatcher = ({ functionMatcher }) => functionMatcher; +const getFunctionMatcher = ({ func }) => func; /** * @type {MatcherGenerator} */ @@ -236,6 +236,6 @@ export const builtInMatchers = [ { name: 'headers', matcher: getHeaderMatcher }, { name: 'params', matcher: getParamsMatcher }, { name: 'body', matcher: getBodyMatcher, usesBody: true }, - { name: 'functionMatcher', matcher: getFunctionMatcher }, + { name: 'func', matcher: getFunctionMatcher }, { name: 'url', matcher: getUrlMatcher }, ]; diff --git a/packages/core/src/Route.js b/packages/core/src/Route.js index d32cf7e6..e7c7814a 100644 --- a/packages/core/src/Route.js +++ b/packages/core/src/Route.js @@ -41,7 +41,7 @@ import statusTextMap from './StatusTextMap'; * @property {{ [key: string]: string }} [query] * @property {{ [key: string]: string }} [params] * @property {object} [body] - * @property {RouteMatcherFunction} [functionMatcher] + * @property {RouteMatcherFunction} [func] * @property {RouteMatcher} [matcher] * @property {RouteMatcherUrl} [url] * @property {RouteResponse | RouteResponseFunction} [response] @@ -139,7 +139,7 @@ class Route { delete this.config.matcher; } if (isFunctionMatcher(this.config.matcher)) { - this.config.functionMatcher = this.config.matcher; + this.config.func = this.config.matcher; } } /** diff --git a/packages/core/src/__tests__/Matchers/function.test.js b/packages/core/src/__tests__/Matchers/function.test.js index 0bc6d4f2..46af89bc 100644 --- a/packages/core/src/__tests__/Matchers/function.test.js +++ b/packages/core/src/__tests__/Matchers/function.test.js @@ -43,7 +43,7 @@ describe('function matching', () => { const route = new Route({ matcher: 'end:profile', response: 200, - functionMatcher: (url, opts) => + func: (url, opts) => opts && opts.headers && opts.headers.authorized === true, }); diff --git a/packages/core/src/__tests__/Matchers/route-config-object.test.js b/packages/core/src/__tests__/Matchers/route-config-object.test.js index b43877c5..b9ad11a3 100644 --- a/packages/core/src/__tests__/Matchers/route-config-object.test.js +++ b/packages/core/src/__tests__/Matchers/route-config-object.test.js @@ -42,10 +42,10 @@ describe('matcher object', () => { }); //TODO be strionger on discouraging this - it.skip('deprecated message on using functionMatcher (prefer matcher)', () => { + it.skip('deprecated message on using func (prefer matcher)', () => { new Route({ url: 'end:profile', - functionMatcher: (url, opts) => + func: (url, opts) => opts && opts.headers && opts.headers.authorized === true, response: 200, });