Skip to content

Commit

Permalink
body option is ignored for get requests
Browse files Browse the repository at this point in the history
  • Loading branch information
leggsimon committed Sep 10, 2019
1 parent b2189c3 commit e856a9b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib/generate-matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ const getFunctionMatcher = ({ matcher, functionMatcher = () => true }) =>
typeof matcher === 'function' ? matcher : functionMatcher;

const getBodyMatcher = ({ body: expectedBody }) => {
return (url, { headers = {}, body }) => {
return (url, { headers = {}, body, method = 'get' }) => {
if (method.toLowerCase() === 'get') {
// GET requests don’t send a body so the body matcher should be ignored for them
return true;
}

const lowerCaseHeaders = headerUtils.toLowerCase(
headerUtils.normalize(headers)
);
Expand Down
12 changes: 12 additions & 0 deletions test/specs/routing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,18 @@ module.exports = fetchMock => {
});
expect(fm.calls(true).length).to.equal(1);
});

it('should ignore the body option matcher if request was GET', async () => {
fm.mock('http://it.at.there/', 200, {
body: {
foo: 'bar',
baz: 'qux'
}
}).catch();

await fm.fetchHandler('http://it.at.there/');
expect(fm.calls(true).length).to.equal(1);
});
});
});

Expand Down

0 comments on commit e856a9b

Please sign in to comment.