I'm trying to assert if response body is empty, but got error:
var api = supertest(TEST_URL);
...
api.get('..')
.expect('Content-Type', /json/)
.end(function (err, res) {
if (err) {
return done(err);
}
res.should.have.status(200);
// Uncaught AssertionError: expected {} to have a property 'length'
// res.body.should.empty;
// Workaround should be used
res.text.should.eql('{}');
What's wrong? How can I fix this issue?
.empty
assertion in should.js
check for string, arguments, arrays just length property. So if it throw assertion about missing length - your body does not looked parsed to json (you need to make sure you return right Content-Type
like application/json
).
For objects yes .empty
will check for missing any enumerable properties.
$ node
> var should = require('should')
undefined
> var res = { body: {} };
undefined
> res.body.should.be.empty
{ obj: {},
params: { operator: 'to be empty' },
negate: false }
>