【发布时间】:2020-10-31 08:35:39
【问题描述】:
我正在尝试在一组对象上使用 Mocha 和 Chai 编写一些测试。我想遍历这个数组并返回任何包含error 键的对象。我认为这种事情会很容易,但我遇到了困难。
[
{ fileName: 'font1.ttc', error: 'font_type_not_supported' },
{ fileName: 'font2.ttf', error: 'parse_failed' },
{ fileName: 'font3.tff' }
]
我已经尝试过类似的东西。
expect(testResult).to.have.nested.property('error');
我可能遗漏了一些简单的东西,有人有什么建议吗?
【问题讨论】:
-
我不知道
chai是否将此作为内置断言。也许只是expect(testResult.some(e => e.error !== undefined)).to.be.true;,假设您正在尝试确定数组中的至少一个对象是否具有所需的键?