0

I try to use supertest-as-promised with chai's expect. The test should go like this: post some JSON the foos endpoint, then call bars endpoint, where the response's body has a length of 2.

  it('should fail', function(){
    var agent = request(app)
    agent
      .post('/foos')
      .send({
        // some JSON
      })
      .then(function(){
        agent.get('/bars').then(function(res){
          console.log(res);
          expect(res).to.have.deep.property('body.data').and.have.property('length').and.equal(3)
        })
      })
  })

console.log does not run, and the test passes no matter what i write to equal.

user3568719
  • 1,036
  • 15
  • 33

1 Answers1

0

Are you sure your promises resolve? Check for this first and second of all use a done callback to notify chai that your async function is finished:

it('should fail', function(done){
    var agent = request(app)
    agent
      .post('/foos')
      .send({
        // some JSON
      })
      .then(function(){
        agent.get('/bars').then(function(res){
          console.log(res);
          expect(res).to.have.deep.property('body.data').and.have.property('length').and.equal(3)
          done();
        }, function(error) {
          console.log(error);
        })
      }, function(error) {
        console.log(error);
      })
  })
Hidde Stokvis
  • 442
  • 3
  • 10