Skip to content

Commit 075a866

Browse files
authored
Merge pull request #24 from zendesk/stef/return_on_investment
[BUG] Fixes an issue where Save Hook rules aren't being respect for synchronous return
2 parents afcc1d9 + 4cd93a9 commit 075a866

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

lib/utils.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,13 @@ function when(items) {
8585
res = item();
8686
if (isPromise(res)) {
8787
promise = res;
88+
} else if (isFalsy(res)) {
89+
promise = Promise.reject(res);
8890
} else {
89-
promise = new Promise(function(resolve) {
90-
resolve(res);
91-
});
91+
promise = Promise.resolve(res);
9292
}
9393
} catch(err) {
94-
promise = new Promise(function(resolve, reject) {
95-
reject(err);
96-
});
94+
promise = Promise.reject(err);
9795
}
9896
} else {
9997
promise = new Promise(function(resolve, reject) {

spec/utils_spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,29 @@ describe('Utils', function() {
5656

5757
});
5858

59+
describe('with one or more functions passed in', function() {
60+
it('should reject when any of the functions returns false', function(done) {
61+
expect(Utils.when([
62+
function() { return false; },
63+
function() { return true; }
64+
])).to.eventually.be.rejected.and.notify(done);
65+
});
66+
67+
it('should reject with a string, when any of the functions returns a string', function(done) {
68+
expect(Utils.when([
69+
function() { return 'Awful mistake'; },
70+
function() { return true; }
71+
])).to.eventually.be.rejectedWith('Awful mistake').and.notify(done);
72+
});
73+
74+
it('should resolve if all of the functions return true', function(done) {
75+
expect(Utils.when([
76+
function() { return true; },
77+
function() { return true; }
78+
])).to.eventually.be.fulfilled.and.notify(done);
79+
});
80+
});
81+
5982
describe('with one or more promises passed in', function() {
6083
var allDone;
6184
beforeEach(function() {

0 commit comments

Comments
 (0)