Write API tests for HTTP DELETE method

--

The HTTP DELETE method is pretty straightforward, it deletes an existing resource and if the resource is already deleted it will most likely throw a ‘not found’ error.

Let’s take a look at an example -

it('DELETE /users/:id', () => {
return request
.delete('users/2')
.set('Authorization', `Bearer ${TOKEN}`)
.then((res) => {
expect(res.body.data).to.be.eq(null);
});
});

This will likely return the body similar to this-

{ code: 204, meta: null, data: null }

And, upon hitting the same request again, you will see a not-found error -

{ code: 404, meta: null, data: { message: 'Resource not found' } }

Check out this video to see a detailed explanation of how to work with the HTTP DELETE method:

You can also clone the GitHub repo to access this code

To learn more about API testing, check out my free tutorial series here -

https://www.youtube.com/watch?v=ZSVw3TyZur4&list=PL6AdzyjjD5HDR2kNRU2dA1C8ydXRAaaBV&ab_channel=AutomationBro

I hope this post helped you out, let me know in the comments below!

Happy testing! 😄

Subscribe to my YouTube channel
Support my work — https://www.buymeacoffee.com/automationbro
Follow @automationbro on Twitter

--

--

Dilpreet Johal
Dilpreet Johal

Written by Dilpreet Johal

SDET Architect | YouTuber | Tech Blogger | Love to explore new tools and technologies. Get access to all the courses— https://sdetunicorns.com/

No responses yet