Skip to content

Commit

Permalink
Merge pull request #494 from wheresrhys/fix-regression-493
Browse files Browse the repository at this point in the history
allow routes using different function matchers
  • Loading branch information
wheresrhys committed Jan 2, 2020
2 parents 6290ca4 + 09bed92 commit f1ce6dc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/compile-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ const sanitizeRoute = route => {
route.url = route.matcher;
delete route.matcher;
}
route.identifier = route.name || route.url;

route.functionMatcher = route.matcher || route.functionMatcher;

route.identifier = route.name || route.url || route.functionMatcher;
return route;
};

Expand Down
26 changes: 26 additions & 0 deletions test/specs/repeat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,32 @@ module.exports = fetchMock => {

expect(() => sb1.fetchHandler('http://it.at.there/')).not.to.throw();
});

it('Allow overwriting routes when using multiple function matchers', async () => {
function matcher1() {
return true;
}

function matcher2() {
return true;
}

const sb = fm.sandbox();

expect(() =>
sb.postOnce(matcher1, 200).postOnce(matcher2, 200)
).not.to.throw();

await sb('https://example.com', { method: 'POST' });
expect(sb.done()).to.be.false;
expect(sb.done(matcher1)).to.be.true;
expect(sb.done(matcher2)).to.be.false;
await sb('https://example.com', { method: 'POST' });

expect(sb.done()).to.be.true;
expect(sb.done(matcher1)).to.be.true;
expect(sb.done(matcher2)).to.be.true;
});
});

describe('strict matching shorthands', () => {
Expand Down

0 comments on commit f1ce6dc

Please sign in to comment.