如何在 AVA 中替换 Chai.js 的`.deep.iterate.over`?

问题描述 投票:0回答:1

我目前正在将一大批测试从Mocha和Chai迁移到AVA。正因为如此,我有时需要替换一些 Chai.js 的断言,以便在 AVA 中使用。

// Before
expect(arr).to.be.iterable;

// After
t.is(typeof arr[Symbol.iterator], 'function');

然而,我不知道如何替换掉 expect(arr)to.deep.iterate.over([]). 我在Chai docs页面上发现了以下内容。

In many cases the array spread operator is the best way to test iterables. chai-iterator is however very useful for testing part of a very long (or infinite) iterable.

不幸的是,链接页面返回404。所以我的问题是--如何替换上面的方法,使我可以在 AVA 中使用?

javascript node.js chai ava
1个回答
1
投票

我不确定这个断言的作用,但我想你可以在 [...arr]? 或者使用 for of 循环,做一些事情?我不知道你的代码库,但这些测试非常特殊。这些测试值得吗?

请注意,你仍然可以在 AVA 中使用 Chai 断言,但你必须将其设置为 failWithoutAssertions 选择 false. 这样一来,如果Chai断言抛出,你的测试就会失败,如果没有,就会通过。

© www.soinside.com 2019 - 2024. All rights reserved.