Skip to content

Commit

Permalink
matchers list is a static property
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Aug 15, 2020
1 parent e8de01c commit fcdfe05
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Route/index.js
@@ -1,5 +1,4 @@
const builtInMatchers = require('./matchers');
const matchers = [];

const { debug, setDebugNamespace, getDebug } = require('../lib/debug');

Expand Down Expand Up @@ -28,7 +27,7 @@ class Route {
throw new Error('fetch-mock: Each route must define a response');
}

if (!matchers.some(({ name }) => name in this)) {
if (!Route.registeredMatchers.some(({ name }) => name in this)) {
throw new Error(
"fetch-mock: Each route must specify some criteria for matching calls to fetch. To match all calls use '*'"
);
Expand Down Expand Up @@ -82,7 +81,7 @@ class Route {
setDebugNamespace('generateMatcher()');
debug('Compiling matcher for route');

const activeMatchers = matchers
const activeMatchers = Route.registeredMatchers
.map(
({ name, matcher, usesBody }) =>
this[name] && { matcher: matcher(this, this.fetchMock), usesBody }
Expand Down Expand Up @@ -140,10 +139,12 @@ class Route {
}

static addMatcher(matcher) {
matchers.push(matcher);
Route.registeredMatchers.push(matcher);
}
}

Route.registeredMatchers = [];

builtInMatchers.forEach(Route.addMatcher);

module.exports = Route;

0 comments on commit fcdfe05

Please sign in to comment.