How custom assertions and order of execution work
masterExpectations in supertest are executed in the order they are defined. This allows you to use a custom .expect(fn) to modify the response object (e.g., normalizing data) before subsequent assertions run.
request(app)
.post('/user')
.send('name=john')
.expect(function(res) {
// Modify response before next assertion
res.body.id = 'some fixed id';
res.body.name = res.body.name.toLowerCase();
})
.expect(200, {
id: 'some fixed id',
name: 'john'
}, done);