Skip to content

Commit

Permalink
feat!: renamed functionMatcher to func
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Jul 20, 2024
1 parent 429a3db commit 4cee629
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/docs/@fetch-mock/core/route/matcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const getFullUrlMatcher = (route, matcherUrl, query) => {
/**
* @type {MatcherGenerator}
*/
const getFunctionMatcher = ({ functionMatcher }) => functionMatcher;
const getFunctionMatcher = ({ func }) => func;
/**
* @type {MatcherGenerator}
*/
Expand Down Expand Up @@ -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 },
];
4 changes: 2 additions & 2 deletions packages/core/src/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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;
}
}
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/Matchers/function.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down

0 comments on commit 4cee629

Please sign in to comment.