Skip to content

Commit

Permalink
Added timeout test;
Browse files Browse the repository at this point in the history
  • Loading branch information
DigitalBrainJS committed Sep 11, 2020
1 parent 9ef70ec commit b41a296
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions test/tests/CPromise.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const assert= require('assert');
const CPromise = require( '../../lib/c-promise');
const {CanceledError}= CPromise;

const delay = (ms, value, options) => new CPromise(resolve => setTimeout(() => resolve(value), ms), options);


module.exports = {
constructor: {
'should create instance of CancelablePromise': function () {
Expand Down Expand Up @@ -142,5 +142,22 @@ module.exports = {
assert.ok(err instanceof CPromise.CanceledError);
})
}
}
},

'timeout': {
'should cancel the chain with timeout reason': async function () {
const p = new CPromise(function (resolve, reject) {
setTimeout(resolve, 1000);
});

return p
.timeout(100)
.then(() => {
assert.fail('chain was not cancelled');
}, err => {
assert.ok(err instanceof CanceledError);
assert.equal(err.message, 'timeout');
})
}
}
};

0 comments on commit b41a296

Please sign in to comment.