Chai - Testing for values in array of objects

后端 未结 6 1312
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-01 12:22

I am setting up my tests for the results to a REST endpoint that returns me an array of Mongo database objects.

[{_id: 5, title: \'Blah\', owner: \'Ted\', de         


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-01 13:02

    As stated here following code works now with chai-like@0.2.14 and chai-things. I just love the natural readability of this approach.

    var chai = require('chai'),
        expect = chai.expect;
    
    chai.use(require('chai-like'));
    chai.use(require('chai-things')); // Don't swap these two
    
    expect(data).to.be.an('array').that.contains.something.like({title: 'Blah'});
    

提交回复
热议问题