Skip to content

Commit e856a9b

Browse files
committed
body option is ignored for get requests
1 parent b2189c3 commit e856a9b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/lib/generate-matcher.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ const getFunctionMatcher = ({ matcher, functionMatcher = () => true }) =>
7474
typeof matcher === 'function' ? matcher : functionMatcher;
7575

7676
const getBodyMatcher = ({ body: expectedBody }) => {
77-
return (url, { headers = {}, body }) => {
77+
return (url, { headers = {}, body, method = 'get' }) => {
78+
if (method.toLowerCase() === 'get') {
79+
// GET requests don’t send a body so the body matcher should be ignored for them
80+
return true;
81+
}
82+
7883
const lowerCaseHeaders = headerUtils.toLowerCase(
7984
headerUtils.normalize(headers)
8085
);

test/specs/routing.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,18 @@ module.exports = fetchMock => {
622622
});
623623
expect(fm.calls(true).length).to.equal(1);
624624
});
625+
626+
it('should ignore the body option matcher if request was GET', async () => {
627+
fm.mock('http://it.at.there/', 200, {
628+
body: {
629+
foo: 'bar',
630+
baz: 'qux'
631+
}
632+
}).catch();
633+
634+
await fm.fetchHandler('http://it.at.there/');
635+
expect(fm.calls(true).length).to.equal(1);
636+
});
625637
});
626638
});
627639

0 commit comments

Comments
 (0)