Reputation: 2094
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);
});
});
Upvotes: 3
Views: 5159
Reputation: 10005
Let me share here an example, using promises, which doesn't require done()
:
describe('PUT: update task (id:5)', function() {
test('It should return response 200.', function() {
return request(app)
.put('/api/v1.0/tasks/5')
.send({title:'Code Refactor API',user:'ivanleoncz'})
.expect(200);
});
});
For more information: https://www.npmjs.com/package/supertest
Upvotes: 1
Reputation: 2094
Added:
it("Respond with 200", function (done) {
request(app)
.put('/')
.send("{}")
.expect(200)
.end(function(err, res) {
done();
})
});
And now it works(?)
Upvotes: 2