Supertest: How to test PUT method with a body in the request?

Created on 23 Jun 2015  路  6Comments  路  Source: visionmedia/supertest

How to test PUT method specifying a body?

Most helpful comment

Try with following using put method instead of post

request(app)
            .post('/login')
            .send({
                username: '[email protected]',
                password: 'password'
            })
            .expect(200)
            .end(function(err, res) {

                expect(res.body.token).to.be.not.undefined;
                expect(res.body.user).to.be.not.undefined;
                expect(res.body.user.username).to.be.eql('[email protected]');

                done();
            })

All 6 comments

Solved, using .send() method

Can you post an example of the solution for the PUT method? Thank you!

Try with following using put method instead of post

request(app)
            .post('/login')
            .send({
                username: '[email protected]',
                password: 'password'
            })
            .expect(200)
            .end(function(err, res) {

                expect(res.body.token).to.be.not.undefined;
                expect(res.body.user).to.be.not.undefined;
                expect(res.body.user.username).to.be.eql('[email protected]');

                done();
            })

Thank you for your response!
I had a problem with put and also trying a file upload, so there was a little problem :)

Hi, for general questions like this, let's try to use StackOverflow with questions tagged supertest

http://stackoverflow.com/questions/tagged/supertest

this https://github.com/visionmedia/supertest/issues/246#issuecomment-121542653 works great with POST too :) thanks for sharing code sample

Was this page helpful?
0 / 5 - 0 ratings