Search code examples
javascriptnode.jstestingsupertesthttp-put

Using PUT method on Supertest


How do I use a PUT method with SuperTest? All I get is "404 Not found" as response.

The request handler:

router.put('/', function (req, res) {
    res.type('json');

    FooResource(req.body, function () {
        res.send("{}");
    });
});

The test suite:

describe("PUT /foo/fii", function () {

    it("Respond with 200", function (done) {

        request(app)
            .put('/')
            .set('Accept', 'application/json')
            .expect(200, done);

    });
});

Solution

  • Added:

        it("Respond with 200", function (done) {
    
            request(app)
                .put('/')
                .send("{}")
                .expect(200)
                .end(function(err, res) {
                    done();
                })
    
        });
    

    And now it works(?)