I am using Mocha with supertest and should
In response I have array of objects e.g.
[{ id: 1, name:'Mark'}, { id: 2, name:'Lucy'}]
it('Should get example names', function ( done ) {
supertest
.get('/someRoute')
.set({
headerData: headerData
})
.expect(200)
.expect(function(res){
(res.body.data).should.be.an.Object();
})
.end( function ( err, res ) {
if ( err ) return done( err );
done();
});
});
I get that the test passes. If if put something else e.g. should.be.a.Number() test will fail and I will get an error.
Questions:
- Why does test pass if I use Object() but not Number() ?
- I know that using arrow functions in Mocha is discouraged - does this apply to supertest as well ( can I write .expect((res)=>{})?
- Should I make assertions as written in example ( separate .except ) or could it be written in the .end block ( I do get failed result either way ) ?
Aucun commentaire:
Enregistrer un commentaire