Assert arrays using Chai (or Should) in Javascript ES6 (using Babel)

前端 未结 1 1187
醉酒成梦
醉酒成梦 2021-01-22 14:11

I\'m trying to test an array such as:

let projects = [
    {  
        \"id\": \"55a75be01fa2c7ff76a2ce7a\",
        \"title: \"Only-Ben\",
        \"other_keys\         


        
相关标签:
1条回答
  • 2021-01-22 14:59

    The second version (with Babel) does not work because your test forgets to call chai.should(). In my testing, once that method call is added, everything works as expected (the test passes).

    It also seems that Bergi was correct in this comment.

    If this does not work for you, it seems that in order to help you, we would need more information. It might help to provide the source code of the babelhook --compilers option you are using. (The standard way of referencing Babel from Mocha's compiler option is mocha --compilers js:babel/register.)

    Here is my test code:

    import chai from 'chai';
    chai.should();
    import chaiThings from "chai-things";
    chai.use(chaiThings);
    
    describe('Array', function() {
       it('Test array', function(cb){
           [{ a: 'cat' }, { a: 'dog' }].should.include.something.that.deep.equals({ a: 'cat' })
            cb();
       });
    });
    
    0 讨论(0)
提交回复
热议问题