summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Early <alexander.early@gmail.com>2019-06-22 20:29:26 -0700
committerAlexander Early <alexander.early@gmail.com>2019-06-22 20:29:26 -0700
commitb5c3f2f462beb73b08c4459ebffe0d748a6e0ddb (patch)
tree771b879bba4374e8f9387006593f52bfb1a0880e
parentbdbf873d7ced48485f0fe0fd328d55d8e8de93ee (diff)
downloadasync-b5c3f2f462beb73b08c4459ebffe0d748a6e0ddb.tar.gz
improve coverage of forEachAsync
-rw-r--r--test/es2017/asyncGenerators.js30
1 files changed, 30 insertions, 0 deletions
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])
+ })
}