I'm having a lot of trouble sending a request body in a supertest post. I've read the solutions to other questions, which blame improper configuration of body-parser, but those answers are referring to a custom datatype. (res.body is empty in this test that uses supertest and Node.js). I configure body-parser like this:
var bodyParser = require('body-parser');
app.use(bodyParser.json({ limit: '50mb', type: 'application/vnd.api+json' }));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
This solution to the post I've provided says "supertest uses this file to determine if you are sending json or not." My content type is actually listed there, so I don't see why this should be a problem.
I am attempting to post a request like so:
it ('creates user', function (done) {
var user = {
firstname: 'Joe',
lastname: 'JoeJoe',
email: 'joe@joe.com',
password: 'spartacus',
};
request(app)
.post('/api/users')
.send(user)
.expect(200)
.expect('Sent email to joe@joe.com', done)
});
});
And I import my app with this line:
var app = require('../server.js');
Where server.js configures my application entirely. Is this application type supported by supertest? Is there a way to force the user data to be noticed as part of req.body?