Skip to content

Commit

Permalink
Update unit tests to use simpler always(done) style
Browse files Browse the repository at this point in the history
  • Loading branch information
briancavalier committed Aug 10, 2012
1 parent 51a12b4 commit 487838a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 81 deletions.
14 changes: 7 additions & 7 deletions test/all.js
Expand Up @@ -16,7 +16,7 @@ buster.testCase('when.all', {
assert.equals(result, []);
},
fail
).then(done, done);
).always(done);
},

'should resolve values array': function(done) {
Expand All @@ -26,7 +26,7 @@ buster.testCase('when.all', {
assert.equals(results, input);
},
fail
).then(done, done);
).always(done);
},

'should resolve promises array': function(done) {
Expand All @@ -36,7 +36,7 @@ buster.testCase('when.all', {
assert.equals(results, [1, 2, 3]);
},
fail
).then(done, done);
).always(done);
},

'should resolve sparse array input': function(done) {
Expand All @@ -46,7 +46,7 @@ buster.testCase('when.all', {
assert.equals(results, input);
},
fail
).then(done, done);
).always(done);
},

'should reject if any input promise rejects': function(done) {
Expand All @@ -56,7 +56,7 @@ buster.testCase('when.all', {
function(failed) {
assert.equals(failed, 2);
}
).then(done, done);
).always(done);
},

'should throw if called with something other than a valid input plus callbacks': function() {
Expand All @@ -76,7 +76,7 @@ buster.testCase('when.all', {
assert.equals(results, expected);
},
fail
).then(done, done);
).always(done);
},

'should resolve to empty array when input promise does not resolve to array': function(done) {
Expand All @@ -85,7 +85,7 @@ buster.testCase('when.all', {
assert.equals(result, []);
},
fail
).then(done, done);
).always(done);
}
});

Expand Down
18 changes: 9 additions & 9 deletions test/chain.js
Expand Up @@ -40,7 +40,7 @@ buster.testCase('when.chain', {
d.promise.then(
function(val) { assert.equals(val, 1); },
function() { fail('promise should not have rejected'); }
).then(done, done);
).always(done);

when.chain(1, d.resolver);
},
Expand All @@ -53,7 +53,7 @@ buster.testCase('when.chain', {
d.promise.then(
function(val) { assert.equals(val, 1); },
function() { fail('promise should not have rejected'); }
).then(done, done);
).always(done);

input = when.defer();
input.resolve(1);
Expand All @@ -67,7 +67,7 @@ buster.testCase('when.chain', {
d.promise.then(
function(val) { assert.equals(val, 2); },
function() { fail('promise should not have rejected'); }
).then(done, done);
).always(done);

when.chain(1, d.resolver, 2);
},
Expand All @@ -80,7 +80,7 @@ buster.testCase('when.chain', {
d.promise.then(
function(val) { assert.equals(val, 2); },
function() { fail('promise should not have rejected'); }
).then(done, done);
).always(done);

input = when.defer();
input.resolve(1);
Expand All @@ -96,7 +96,7 @@ buster.testCase('when.chain', {
d.promise.then(
function() { fail('promise should not have resolved'); },
function (val) { assert.equals(val, 1); }
).then(done, done);
).always(done);

input = when.defer();
input.reject(1);
Expand All @@ -112,7 +112,7 @@ buster.testCase('when.chain', {
d.promise.then(
function() { fail('promise should not have resolved'); },
function (val) { assert.equals(val, 1); }
).then(done, done);
).always(done);

input = when.defer();
input.reject(1);
Expand All @@ -131,7 +131,7 @@ buster.testCase('when.chain', {
when.chain(input, d).then(
function(val) { assert.equals(val, 1); },
function() { fail('promise should not have rejected'); }
).then(done, done);
).always(done);
},

'should return a preomise that resolves with the optional resolution value': function(done) {
Expand All @@ -145,7 +145,7 @@ buster.testCase('when.chain', {
when.chain(input, d, 2).then(
function(val) { assert.equals(val, 2); },
function() { fail('promise should not have rejected'); }
).then(done, done);
).always(done);
},

'should return a promise that rejects with the input promise rejection value': function(done) {
Expand All @@ -159,7 +159,7 @@ buster.testCase('when.chain', {
when.chain(input, d).then(
function() { fail('promise should not have resolved'); },
function(val) { assert.equals(val, 1); }
).then(done, done);
).always(done);
}

})
Expand Down
22 changes: 11 additions & 11 deletions test/promise.js
Expand Up @@ -68,7 +68,7 @@ buster.testCase('promise', {
assert.equals(val, 1);
},
fail
).then(done, done);
).always(done);

d.resolve(1);
},
Expand All @@ -86,7 +86,7 @@ buster.testCase('promise', {
assert.equals(val, 2);
},
fail
).then(done, done);
).always(done);

d.resolve(1);
},
Expand All @@ -104,7 +104,7 @@ buster.testCase('promise', {
refute.defined(val);
},
fail
).then(done, done);
).always(done);

d.resolve(1);
},
Expand All @@ -125,7 +125,7 @@ buster.testCase('promise', {
refute.defined(val);
},
fail
).then(done, done);
).always(done);

d.reject(1);
},
Expand All @@ -145,7 +145,7 @@ buster.testCase('promise', {
assert.equals(val, 2);
},
fail
).then(done, done);
).always(done);

d.resolve(1);
},
Expand All @@ -165,7 +165,7 @@ buster.testCase('promise', {
function(val) {
assert.equals(val, 2);
}
).then(done, done);
).always(done);

d.resolve(1);
},
Expand All @@ -183,7 +183,7 @@ buster.testCase('promise', {
function(val) {
assert.equals(val, 2);
}
).then(done, done);
).always(done);

d.resolve(1);
},
Expand All @@ -201,7 +201,7 @@ buster.testCase('promise', {
assert.equals(val, 2);
},
fail
).then(done, done);
).always(done);

d.reject(1);
},
Expand All @@ -221,7 +221,7 @@ buster.testCase('promise', {
assert.equals(val, 2);
},
fail
).then(done, done);
).always(done);

d.reject(1);
},
Expand All @@ -239,7 +239,7 @@ buster.testCase('promise', {
function(val) {
assert.equals(val, 2);
}
).then(done, done);
).always(done);

d.reject(1);
},
Expand All @@ -259,7 +259,7 @@ buster.testCase('promise', {
function(val) {
assert.equals(val, 2);
}
).then(done, done);
).always(done);

d.reject(1);
},
Expand Down
6 changes: 3 additions & 3 deletions test/reject.js
Expand Up @@ -16,7 +16,7 @@ buster.testCase('when.reject', {
function(value) {
assert.equals(value, expected);
}
).then(done, done);
).always(done);
},

'should reject a resolved promise': function(done) {
Expand All @@ -31,7 +31,7 @@ buster.testCase('when.reject', {
function(value) {
assert.equals(value, expected);
}
).then(done, done);
).always(done);
},

'should reject a rejected promise': function(done) {
Expand All @@ -46,7 +46,7 @@ buster.testCase('when.reject', {
function(value) {
assert.equals(value, expected);
}
).then(done, done);
).always(done);
}


Expand Down
43 changes: 12 additions & 31 deletions test/some.js
Expand Up @@ -42,41 +42,29 @@ buster.testCase('when.some', {
when.some([], 1,
function(result) {
assert.equals(result, []);
done();
},
function() {
buster.fail();
done();
}
);
fail
).always(done);
},

'should resolve values array': function(done) {
var input = [1, 2, 3];
when.some(input, 2,
function(results) {
assert(subset(results, input));
done();
},
function() {
buster.fail();
done();
}
);
fail
).always(done);
},

'should resolve promises array': function(done) {
var input = [resolved(1), resolved(2), resolved(3)];
when.some(input, 2,
function(results) {
assert(subset(results, [1, 2, 3]));
done();
},
function() {
buster.fail();
done();
}
);
fail
).always(done);
},

'should resolve sparse array input': function(done) {
Expand All @@ -86,25 +74,18 @@ buster.testCase('when.some', {
assert(subset(results, input));
done();
},
function() {
buster.fail();
done();
}
);
fail
).always(done);
},

'should reject if any input promise rejects before desired number of inputs are resolved': function(done) {
var input = [resolved(1), rejected(2), resolved(3)];
when.some(input, 2,
function() {
buster.fail();
done();
},
fail,
function(failed) {
assert.equals(failed, 2);
done();
}
);
).always(done);
},

'should throw if called with something other than a valid input, count, and callbacks': function() {
Expand All @@ -124,7 +105,7 @@ buster.testCase('when.some', {
assert.equals(results, expected.slice(0, 2));
},
fail
).then(done, done);
).always(done);
},

'should resolve to empty array when input promise does not resolve to array': function(done) {
Expand All @@ -133,7 +114,7 @@ buster.testCase('when.some', {
assert.equals(result, []);
},
fail
).then(done, done);
).always(done);
}


Expand Down

0 comments on commit 487838a

Please sign in to comment.