Skip to content

Commit 891197c

Browse files
committed
fix: allow matching body for delete requests
1 parent 51777ec commit 891197c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/fetch-mock/src/Matchers.ts

Lines changed: 1 addition & 1 deletion
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

Lines changed: 19 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy