assert.propContains()
追加されたバージョン: 2.18.0.
説明
propContains( actual, expected, message = "" )
オブジェクトに特定のプロパティが含まれているかどうかをチェックします。
名前 | 説明 |
---|---|
actual |
テストされる式 |
expected |
既知の比較値 |
message (文字列) |
実際の式の簡単な説明 |
propContains
アサーションは、expected オブジェクト内のプロパティのサブセットのみを比較し、これらのキーが厳密に等しい値を持つ独自のプロパティとして存在することをテストします。
このメソッドは再帰的で、入れ子になったオブジェクトの部分的な比較も可能にします。
関連項目
assert.propEqual()
を使用してすべてのプロパティを比較し、余分なプロパティを予期しないものとして考慮します。assert.notPropContains()
を使用して、プロパティがないか、または不平等であるかどうかをテストします。
例
QUnit.test('example', assert => {
const result = {
foo: 0,
vehicle: {
timeCircuits: 'on',
fluxCapacitor: 'fluxing',
engine: 'running'
},
quux: 1
};
assert.propContains(result, {
foo: 0,
vehicle: { fluxCapacitor: 'fluxing' }
});
function Point (x, y) {
this.x = x;
this.y = y;
}
assert.propContains(
new Point(10, 20),
{ y: 20 }
);
assert.propContains(
[ 'a', 'b' ],
{ 1: 'b' }
);
const nested = {
north: [ /* ... */ ],
east: new Point(10, 20),
south: [ /* ... */ ],
west: [ /* ... */ ]
};
assert.propContains(nested, { east: new Point(10, 20) });
assert.propContains(nested, { east: { x: 10, y: 20 } });
assert.propContains(nested, { east: { x: 10 } });
});