Skip to content

Commit

Permalink
improve coverage of forEachAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
aearly committed Jun 23, 2019
1 parent bdbf873 commit b5c3f2f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/es2017/asyncGenerators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
})
}

0 comments on commit b5c3f2f

Please sign in to comment.