Skip to content

Commit 686ab2e

Browse files
authored
Merge pull request #921 from pbomb/pbomb-delete-body
fix: allow matching body for delete requests
2 parents 51777ec + 891197c commit 686ab2e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/fetch-mock/src/Matchers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ const getBodyMatcher: MatcherGenerator = (route) => {
212212
}
213213

214214
return ({ options: { body, method = 'get' } }) => {
215-
if (['get', 'head', 'delete'].includes(method.toLowerCase())) {
215+
if (['get', 'head'].includes(method.toLowerCase())) {
216216
// GET requests don’t send a body so even if it exists in the options
217217
// we treat as no body because it would never actually make it to the server
218218
// in the application code

packages/fetch-mock/src/__tests__/Matchers/body.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,25 @@ describe('body matching', () => {
144144
).toBe(true);
145145
});
146146

147+
it('should match if request is delete', () => {
148+
const route = new Route({
149+
body: { foo: 'bar' },
150+
method: 'delete',
151+
response: 200,
152+
});
153+
154+
expect(
155+
route.matcher({
156+
url: 'http://a.com/',
157+
options: {
158+
method: 'DELETE',
159+
body: JSON.stringify({ foo: 'bar' }),
160+
headers: { 'Content-Type': 'application/json' },
161+
},
162+
}),
163+
).toBe(true);
164+
});
165+
147166
describe('partial body matching', () => {
148167
it('match when missing properties', () => {
149168
const route = new Route({

0 commit comments

Comments
 (0)