It seems that regardless of what I include with send(), the request body remains empty. Headers and params are both exactly as expected.
var request = require('supertest')
, express = require('express');
describe('Supertest example', function() {
it('should return a request body', function(done) {
var app = express();
app.post('/foo/:example', function(req, res) {
console.log('\n');
console.log('Body: ' + req.body);
console.log('Params: ' + req.params.example);
console.log('Headers: ' + req.headers['x-blargh-header']);
res.send('bar')
});
request(app)
.post('/foo/example-param')
.set('X-Blargh-Header', 'woot')
.send({neato: true})
.expect(200, done);
});
});
The console logs from that return:
Body: undefined
Params: example-param
Headers: woot
As far as I can tell, I'm not doing anything differently from the tests for send(). I've been banging my head against this for a few hours now, so any ideas would be welcome.
Aaaand I'm an idiot. I was forgetting to use the bodyParser middleware.
Most helpful comment
Aaaand I'm an idiot. I was forgetting to use the bodyParser middleware.