Match partial objects in Chai assertions?

前端 未结 8 2066
谎友^
谎友^ 2021-01-07 18:07

I am looking for the best way to match the following:

expect([
    {
        C1: \'xxx\',
        C0: \'this causes it not to match.\'
    }
]).to.deep.incl         


        
8条回答
  •  隐瞒了意图╮
    2021-01-07 18:46

    Clean, functional and without dependencies

    simply use a map to filter the key you want to check

    something like:

    const array = [
        {
            C1: 'xxx',
            C0: 'this causes it not to match.'
        }
    ];
    
    expect(array.map(e=>e.C1)).to.include("xxx");
    

    https://www.chaijs.com/api/bdd/

提交回复
热议问题