assert.notPropContains()
添加版本:2.18.0.
描述
notPropContains( actual, expected, message = "" )
检查对象是否不包含某些属性。
名称 | 描述 |
---|---|
实际 |
正在测试的表达式 |
预期 |
已知比较值 |
message (字符串) |
简短描述 |
notPropContains
断言比较预期对象中属性的子集,并测试这些键是否不存在或根据严格相等比较持有不同的值。
此方法是递归的,也允许对嵌套对象进行部分比较。
另请参阅
- 使用
assert.propContains()
来测试属性的存在和相等性。
示例
QUnit.test('example', assert => {
const result = {
foo: 0,
vehicle: {
timeCircuits: 'on',
fluxCapacitor: 'fluxing',
engine: 'running'
},
quux: 1
};
// succeeds, property "timeCircuits" is actually "on"
assert.notPropContains(result, {
vehicle: {
timeCircuits: 'off'
}
});
// succeeds, property "wings" is not in the object
assert.notPropContains(result, {
vehicle: {
wings: 'flapping'
}
});
function Point (x, y) {
this.x = x;
this.y = y;
}
assert.notPropContains(
new Point(10, 20),
{ z: 30 }
);
const nested = {
north: [ /* ... */ ],
east: new Point(10, 20),
south: [ /* ... */ ],
west: [ /* ... */ ]
};
assert.notPropContains(nested, { east: new Point(88, 42) });
assert.notPropContains(nested, { east: { x: 88 } });
});