Skip to content

Commit b4a0f9b

Browse files
committed
tests for ctx.cancel
1 parent 072b695 commit b4a0f9b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

spec/context.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,32 @@ describe('Context', () => {
5555
});
5656
});
5757

58+
describe('cancel', () => {
59+
const ctx = new Context({});
60+
it('aborts an execution', (done) => {
61+
let spy = sinon.spy();
62+
ctx.done = done;
63+
ctx.start((ctx, done) => {
64+
setTimeout(spy, 1000);
65+
});
66+
ctx.cancel();
67+
expect(spy).to.not.have.been.called;
68+
ctx.stop();
69+
done();
70+
});
71+
it('calls clearTimeout', (done) => {
72+
let spy = sinon.spy(global, 'clearTimeout');
73+
ctx.done = done;
74+
ctx.start((ctx, done) => {
75+
setTimeout(done, 1000);
76+
});
77+
ctx.cancel();
78+
expect(spy).to.have.been.called;
79+
ctx.stop();
80+
done();
81+
});
82+
});
83+
5884
describe('#retryable', () => {
5985
it('Returns the date/time it is going to retry', () => {
6086
const ctx = new Context({
@@ -119,6 +145,7 @@ describe('Context', () => {
119145
expect(ctx.repeatable()).to.be.equal(false);
120146
});
121147
});
148+
122149
describe('#next', () => {
123150
let task = {};
124151
const job = (ctx, done) => {

0 commit comments

Comments
 (0)