Commit dc6ce37a authored by Stefan Penner's avatar Stefan Penner

Merge pull request #3 from teddyzeenny/fix_callback_assimilation

Run reduce tests only in node
parents 2158a5a9 dfa0a156
......@@ -979,50 +979,56 @@ describe("RSVP extensions", function() {
});
});
// thanks to @wizardwerdna for the test case -> https://github.com/tildeio/rsvp.js/issues/66
describe("using reduce to sum integers using promises", function(){
var resolve = RSVP.resolve;
// Only run these tests in node (phantomjs cannot handle them)
if (typeof module !== 'undefined' && module.exports) {
it("should build the promise pipeline without error", function(){
var array, iters, pZero, i;
describe("using reduce to sum integers using promises", function(){
var resolve = RSVP.resolve;
array = [];
iters = 1000;
it("should build the promise pipeline without error", function(){
var array, iters, pZero, i;
for (i=1; i<=iters; i++) {
array.push(i);
}
array = [];
iters = 1000;
pZero = resolve(0);
for (i=1; i<=iters; i++) {
array.push(i);
}
array.reduce(function(promise, nextVal) {
return promise.then(function(currentVal) {
return resolve(currentVal + nextVal);
});
}, pZero);
});
pZero = resolve(0);
it("should get correct answer without blowing the nextTick stack", function(done){
var pZero, array, iters, result, i;
array.reduce(function(promise, nextVal) {
return promise.then(function(currentVal) {
return resolve(currentVal + nextVal);
});
}, pZero);
});
pZero = resolve(0);
it("should get correct answer without blowing the nextTick stack", function(done){
var pZero, array, iters, result, i;
array = [];
iters = 1000;
pZero = resolve(0);
for (i=1; i<=iters; i++) {
array.push(i);
}
array = [];
iters = 1000;
result = array.reduce(function(promise, nextVal) {
return promise.then(function(currentVal) {
return resolve(currentVal + nextVal);
});
}, pZero);
for (i=1; i<=iters; i++) {
array.push(i);
}
result = array.reduce(function(promise, nextVal) {
return promise.then(function(currentVal) {
return resolve(currentVal + nextVal);
});
}, pZero);
result.then(function(value){
assert.equal(value, (iters*(iters+1)/2));
done();
result.then(function(value){
assert.equal(value, (iters*(iters+1)/2));
done();
});
});
});
});
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment