Search code examples
javascriptnode.jschaiava

How to replace Chai.js' `.deep.iterate.over` in AVA?


I'm currently in process of migrating a large set of tests from Mocha and Chai to AVA. Because of that, I sometimes have to replace some Chai.js assertions to use them in AVA, example:

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

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

However, I'm not sure how to replace expect(arr)to.deep.iterate.over([]). I found the following on the Chai docs page:

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.

Unfortunately, the linked page returns 404. So my question is - how do I replace the method above, so that I can use it with AVA?


Solution

  • I'm not sure what that assertion does, but I suppose you could assert something on [...arr]? Or use a for / of loop that does something? I don't know your codebase but these are some awfully specific tests. Are they even worth it?

    Note that you can still use Chai assertions in AVA, but you'll have to set the failWithoutAssertions option to false. That way if the Chai assertion throws, your test fails, and if it doesn't, it passes.