I tried to use this module to test my express app. But I got a strange error.
You may can reproduce it, if you try the following code with mocha. it based on your example.js:
var request = require('supertest')
, express = require('express');
var app = express();
app.get('/user', function(req, res){
res.format({
json : function(req, res, next) {
res.send( { name: 'tobi' } );
}
});
});
describe('GET /users', function(){
it('respond with json', function(done){
request(app)
.get('/user')
.set('Accept', 'application/json')
.expect('Content-Length', '20')
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res){
if (err) { return done(err); }
done();
});
});
});
GET /users
1) respond with json
ร 1 of 1 test failed:
1) GET /users respond with json:
Error: expected undefined response body, got '{\n "name": "tobi"\n}'