2017-05-31 3 views
1

私はオブジェクトを渡すことができますどのように把握し、オブジェクトがthat.includesまたはto.includeのいずれかを使用して応答している場合だけでチャイチャイのインクルードの使い方は?

からチェックしようとしている私は私の問題をチェックするための簡単なフィドルを書いた:

https://jsfiddle.net/balexandre/4Loupnjk/2/

https://jsfiddle.net/balexandre/4Loupnjk/5/フラグ.deep

var e = { 
    "results": { 
    "total_rejected_recipients": 0, 
    "total_accepted_recipients": 1, 
    "id":"102618457586465882" 
    } 
}; 

私の理解から、eオブジェクトは実際にはもっと小さいオブジェクトが含まれているはずです...または何かが欠けていますか?

expect(e).to.include({ 
    "results": { 
    "total_rejected_recipients": 0, 
    "total_accepted_recipients": 1 
    } 
}); 

が、私はエラーを取得:しかし、このフレームワーク上

assertionError: expected { Object (results) } to have property 'results' of { Object (total_rejected_recipients, total_accepted_recipients) }, but got { Object (total_rejected_recipients, total_accepted_recipients, ...) } 
at Context.<anonymous> (:73:18) 

まず時間が、問題になる可能性があります:)

+0

私にはバグのようです。一時的な代替手段はhttps://www.npmjs.com/package/chai-subsetを使用しています。 – Ioan

答えて

3

まず第一に、あなたはあなたのように、deep.includeアサーションを使用する必要がありますそこには深い目的があります。

とにかく、これはバグのようです。これが実装されたgithubチケットは、hereと関連するコミットhereにあります。

この主張のためのテストカバレッジはここにある:より良い

expect({ foo: obj1, bar: obj2 }).to.deep.include({ foo: { a: 1 }, bar: { } }); 

chaiリポジトリに問題を開いて、一時的に使用chai-subsetパッケージ:

expect({foo: obj1, bar: obj2}).to.deep.include({foo: {a: 1}}); 
expect({foo: obj1, bar: obj2}).to.deep.include({foo: {a: 1}, bar: {b: 2}}); 
expect({foo: obj1, bar: obj2}).to.not.deep.include({foo: {a: 9}}); 
expect({foo: obj1, bar: obj2}).to.not.deep.include({foo: {z: 1}}); 
expect({foo: obj1, bar: obj2}).to.not.deep.include({baz: {a: 1}}); 
expect({foo: obj1, bar: obj2}).to.not.deep.include({foo: {a: 1}, bar: {b: 9}}); 

しかし、それは次のシナリオで壊れます。

+0

'#983](https://github.com/chaijs/chai/issues/983)でも' .deep'と同じエラーがスローされます:(しかし、私が後に残していたことを教えてくれてありがとう。 – balexandre