Skip to content

Commit 106e405

Browse files
committedMay 26, 2016
test bluebird try/catch
1 parent 73059c8 commit 106e405

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed
 

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "common-errors",
33
"author": "David Fenster <david@dfenster.com>",
44
"description": "Common error classes and utility functions",
5-
"version": "0.5.4",
5+
"version": "0.5.5",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/shutterstock/node-common-errors.git"
@@ -14,6 +14,7 @@
1414
}
1515
],
1616
"dependencies": {
17+
"bluebird": "^3.4.0"
1718
},
1819
"devDependencies": {
1920
"mocha": "*",

‎tests/already-in-use.js

+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var assert = require('assert');
2+
var Promise = require('bluebird');
23
var errors = require('..');
34
var name = "AlreadyInUseError";
45
var Err = errors[name];
@@ -10,5 +11,15 @@ describe(name, function(){
1011
assert.equal(error.message, "The specified 'Entity' value is already in use for: att1, att2, att3, att4");
1112
assert.ok(new RegExp(error.name + ": " + error.message + "\n(.*\n)+").test(error.stack), "Stack is good");
1213
assert.ok(error instanceof Error, "It is an instanceof Error");
14+
15+
var caught_error_in_promise = false;
16+
var promise = new Promise(function(res, rej) { res(true); }).then(function(){
17+
throw new opts.extends("test error");
18+
}).catch(Error, function(e){
19+
caught_error_in_promise = true;
20+
}).finally(function(){
21+
assert.ok(caught_error_in_promise, "caught promise error");
22+
});
23+
1324
});
1425
});

‎tests/support/index.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var assert = require('assert');
22
var errors = require('../..');
3+
var Promise = require('bluebird');
34

45
module.exports.testError = function testError(name, opts){
56
opts = opts || {};
@@ -13,7 +14,17 @@ module.exports.testError = function testError(name, opts){
1314
assert.equal(error.message, opts.message_to_assert);
1415
assert.ok(new RegExp(error.name + ": " + error.message + "\n(.*\n)+").test(error.stack), "Stack is good");
1516
assert.equal(Err.super_.name, opts.extends.name, "It is an instance of" + opts.extends.name);
16-
assert.ok(error instanceof Error, opts.extends, "It is an instanceof " + opts.extends.name);
17+
assert.ok(error instanceof Error, "It is an instanceof Error");
18+
assert.ok(error instanceof opts.extends, "It is an instanceof " + opts.extends.name);
19+
20+
var caught_error_in_promise = false;
21+
var promise = new Promise(function(res, rej) { res(true); }).then(function(){
22+
throw new opts.extends("test error");
23+
}).catch(opts.extends, function(e){
24+
caught_error_in_promise = true;
25+
}).finally(function(){
26+
assert.ok(caught_error_in_promise, "caught promise error");
27+
});
1728
}
1829

1930
describe(name, function(){

0 commit comments

Comments
 (0)
Please sign in to comment.