Chai-as-promised, Promised array must be loosely-equal

682 Views Asked by At

Is there a way to assert that a promise array equals your gold standard, minus ordering? Deep equal fails because the ordering isn't guaranteed - the array is being built asynchronously.

As far as I can tell, CaP doesn't include a ".should.eventually.include.all([])" or anything like that. I don't think I'd be able to check every entry, because then where would the notify(done) be chained?

2

There are 2 best solutions below

0
On

The Chai Things plugin might help you.

You could for example do something like:

.should.eventually.include.something.that.equals(promiseA);
.should.eventually.include.something.that.equals(promiseB);
.should.eventually.include.something.that.equals(promiseC);
0
On

If I understand your question correctly you should be able to do it like this:

        Promise.all(arrayOfPromises).then(function (results) {
            //so check your results here
            for (var i = 0; i < results.length; i++) {
                results[i].should.have....
            }

           //and the notify(done) is chained after this
        }).should.eventually.notify(done);

I hope that helps.