Commit 77df9da7 authored by Romain Courteaud's avatar Romain Courteaud 🐙

test queue.cancel

parent 5cf9be38
......@@ -2211,8 +2211,10 @@ describe("`RSVP.Queue`", function () {
});
it('should throw if the queue is rejected', function (done) {
var queue = new RSVP.Queue();
queue.cancel();
var queue = new RSVP.Queue()
.push(undefined, function () {
return RSVP.reject(1);
});
setTimeout(function() {
assert.throws(function () {
......@@ -2221,6 +2223,15 @@ describe("`RSVP.Queue`", function () {
done();
}, 20);
});
it('should throw if the queue is cancelled', function () {
var queue = new RSVP.Queue();
queue.cancel();
assert.throws(function () {
queue.push();
}, RSVP.ResolvedQueueError);
});
});
describe("`Queue` instance", function () {
......@@ -2251,7 +2262,7 @@ describe("`RSVP.Queue`", function () {
it('get the fulfillmentValue of the last queue entry', function (done) {
var queue = new RSVP.Queue();
queue.push(function () {
return "foo"
return "foo";
});
setTimeout(function() {
......@@ -2326,25 +2337,120 @@ describe("`RSVP.Queue`", function () {
done();
}, 20);
});
});
describe("`cancel`", function () {
it('cancel also cancels the remaining promise', function (done) {
it('should be a function', function () {
var queue = new RSVP.Queue();
assert.equal(typeof queue.cancel, "function");
});
it('should reject with a CancellationError', function (done) {
var queue = new RSVP.Queue(),
pushed_result;
queue.push(function () {
return RSVP.timeout(1);
});
queue.push(undefined, function (value) {
pushed_result = value;
throw value;
error;
queue.then(null, function(e) {
error = e;
});
queue.cancel();
setTimeout(function() {
assert(pushed_result instanceof RSVP.CancellationError);
assert(error instanceof RSVP.CancellationError);
assert.equal(queue.isRejected, true);
assert(queue.rejectedReason instanceof RSVP.CancellationError);
done();
}, 20);
});
it('does nothing on a `fulfilled` queue', function (done) {
var queue = new RSVP.Queue()
.push(function () {
return 'ok';
}),
result = 'MARKER1',
error = 'MARKER2';
queue.then(function(e) {
result = e;
});
queue.fail(function(e) {
error = e;
});
setTimeout(function() {
queue.cancel();
setTimeout(function() {
assert.equal(queue.isRejected, undefined);
assert.equal(queue.isFulfilled, true);
assert.equal(queue.fulfillmentValue, 'ok');
assert.equal(result, 'ok');
assert.equal(error, 'MARKER2');
done();
}, 20);
}, 20);
});
it('does nothing on a `rejected` queue', function (done) {
var queue = new RSVP.Queue()
.push(function () {
throw 'ko';
}),
result = 'MARKER1',
error = 'MARKER2';
queue.then(function(e) {
result = e;
});
queue.fail(function(e) {
error = e;
});
setTimeout(function() {
queue.cancel();
setTimeout(function() {
assert.equal(queue.isRejected, true);
assert.equal(queue.isFulfilled, undefined);
assert.equal(queue.rejectedReason, 'ko');
assert.equal(result, 'MARKER1');
assert.equal(error, 'ko');
done();
}, 20);
}, 20);
});
it('should `cancel` pending success `thenable`', function (done) {
var thenable_cancel_called = false,
thenable_ongoing = false,
queue = new RSVP.Queue()
.push(function () {
return new Promise(
function () {
thenable_ongoing = true;
},
function () {
thenable_cancel_called = true;
});
}),
result = 'MARKER1',
error = 'MARKER2';
queue.then(function(e) {
result = e;
});
queue.fail(function(e) {
error = e;
});
setTimeout(function() {
assert.equal(queue.isRejected, undefined);
assert.equal(queue.isFulfilled, undefined);
assert.equal(thenable_ongoing, true);
queue.cancel();
assert.equal(thenable_cancel_called, true);
setTimeout(function() {
assert.equal(queue.isRejected, true);
assert.equal(queue.isFulfilled, undefined);
assert(queue.rejectedReason instanceof RSVP.CancellationError);
assert.equal(result, 'MARKER1');
assert(error instanceof RSVP.CancellationError);
done();
}, 20);
}, 20);
});
});
});
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