-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure sync errors are thrown, and don't callback twice
- Loading branch information
Showing
2 changed files
with
51 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
const eachAsync = require('../../lib/core/utils').eachAsync; | ||
const expect = require('chai').expect; | ||
|
||
describe('utils', function() { | ||
describe('eachAsync', function() { | ||
it('should callback with an error', function(done) { | ||
eachAsync( | ||
[{ error: false }, { error: true }], | ||
(item, cb) => { | ||
cb(item.error ? new Error('error requested') : null); | ||
}, | ||
err => { | ||
expect(err).to.exist; | ||
done(); | ||
} | ||
); | ||
}); | ||
|
||
it('should propagate a synchronously thrown error', function(done) { | ||
expect(() => | ||
eachAsync( | ||
[{}], | ||
() => { | ||
throw new Error('something wicked'); | ||
}, | ||
err => { | ||
expect(err).to.not.exist; | ||
done(err); | ||
} | ||
) | ||
).to.throw(/something wicked/); | ||
done(); | ||
}); | ||
}); | ||
}); |