dimanche 17 novembre 2019

supertest ( should ) - Array of objects passes as an Object type

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:

  1. Why does test pass if I use Object() but not Number() ?
  2. I know that using arrow functions in Mocha is discouraged - does this apply to supertest as well ( can I write .expect((res)=>{})?
  3. 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