From b5c3f2f462beb73b08c4459ebffe0d748a6e0ddb Mon Sep 17 00:00:00 2001 From: Alexander Early Date: Sat, 22 Jun 2019 20:29:26 -0700 Subject: improve coverage of forEachAsync --- test/es2017/asyncGenerators.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/es2017/asyncGenerators.js b/test/es2017/asyncGenerators.js index 61ac964..0fe8ac6 100644 --- a/test/es2017/asyncGenerators.js +++ b/test/es2017/asyncGenerators.js @@ -84,4 +84,34 @@ module.exports = function () { } ) }); + + it('should handle async iterables in each (errors)', (done) => { + const calls = [] + async.each(new AsyncIterable(5), + async (val) => { + calls.push(val) + if (val === 3) throw new Error('fail') + await delay(5) + }, (err) => { + expect(err.message).to.equal('fail') + expect(calls).to.eql([0, 1, 2, 3]) + done() + } + ) + }) + + it('should handle async iterables in each (cancelled)', async () => { + const calls = [] + async.each(new AsyncIterable(5), + (val, cb) => { + calls.push(val) + if (val === 3) cb(false) + cb() + }, () => { + throw new Error('should not get here') + } + ) + await delay(10) + expect(calls).to.eql([0, 1, 2, 3]) + }) } -- cgit v1.2.1