-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for
CanceledError.rethrow
method;
Refactored;
- Loading branch information
1 parent
8c9746b
commit e3d9f6f
Showing
4 changed files
with
62 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const assert = require('assert'); | ||
const {CPromise, E_REASON_TIMEOUT, E_REASON_DISPOSED} = require('../../lib/c-promise'); | ||
const {CanceledError} = CPromise; | ||
|
||
module.exports = { | ||
'CanceledError.throw': { | ||
'should throw the error that is instance of CanceledError': function () { | ||
const originalErr = new CanceledError(); | ||
try { | ||
CanceledError.rethrow(originalErr); | ||
} catch (err) { | ||
assert.strictEqual(err, originalErr); | ||
} | ||
}, | ||
|
||
'should throw the error only if some error code matched': function () { | ||
const originalErr = new CanceledError(E_REASON_TIMEOUT); | ||
try { | ||
CanceledError.rethrow(originalErr, E_REASON_DISPOSED); | ||
} catch (err) { | ||
assert.fail('should not throw'); | ||
} | ||
|
||
try { | ||
CanceledError.rethrow(originalErr, E_REASON_TIMEOUT); | ||
} catch (err) { | ||
assert.strictEqual(err, originalErr); | ||
} | ||
} | ||
} | ||
} | ||
|