0

So I'm trying to test for the values of Boolean property in an array of object. Currently I'm using this code which doesn't seem to work.

describe('/GET/deleted', () => {
    it('should get all objects that are deleted', (done) => {
        chai.request(server)
            .get('/api/object/deleted')
            .set('Cookie', cookie)
            .end((err, res) => {
                res.should.have.status(200);
                res.body.should.be.a('array');
                expect(res.body).to.have.deep.property('[0].deleted', true);
                done();
            });
    });
})

How would you test for the values of a boolean property in an array of objects. Any help would be appreciated. Thanks!

rtn
  • 127,556
  • 20
  • 111
  • 121
BleachedAxe
  • 393
  • 2
  • 5
  • 20

1 Answers1

2

Like from here, this will make sure each object in the array contains a property deleted equal to true.

var chai = require('chai');
var expect = chai.expect;
chai.use(require('chai-things'));

var data = [{deleted:true, other:'stuff'}, {deleted:true, more:'thigns'}];

expect(data).all.have.property('deleted', true);
Diego Goding
  • 516
  • 4
  • 6