Supertest: Request body empty regardless of send method

Created on 28 Feb 2014  路  1Comment  路  Source: visionmedia/supertest

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.

Most helpful comment

Aaaand I'm an idiot. I was forgetting to use the bodyParser middleware.

>All comments

Aaaand I'm an idiot. I was forgetting to use the bodyParser middleware.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nitrocode picture nitrocode  路  4Comments

rkmax picture rkmax  路  5Comments

EverettQuebral picture EverettQuebral  路  3Comments

lovelydreamer picture lovelydreamer  路  4Comments

schm1ty1 picture schm1ty1  路  4Comments