-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
50 lines (43 loc) · 1.44 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
var test = require('tape');
var bluebirdify = require('./index.js');
var Bluebird = require('bluebird');
var uncaughtCaught = false;
test('bluebirdify module', function(t) {
t.plan(3);
t.notEqual(Bluebird, Promise, 'default promise !== Bluebird promise');
bluebirdify({
onuncaught: function(error) {
uncaughtCaught = true;
}
});
t.equal(Bluebird, Promise, 'default === Bluebird promise post bluebirdify');
Promise.reject();
setTimeout(function() {
delete bluebirdify.onuncaught; // teardown
t.ok(uncaughtCaught, 'uncaught promise rejection caught by base hander'); // see prior test
t.end();
}, 10);
});
test('bluebirdify explicit handler', function(t) {
t.plan(1);
bluebirdify.chirp(function() {
t.ok(true, 'explicit handler executed');
t.end();
});
Promise.reject();
});
test('bluebirdify onuncaught, no handler', function(t) {
t.plan(1);
bluebirdify.chirp();
setTimeout(function() {
delete bluebirdify.onuncaught; // teardown
t.ok(uncaughtCaught, 'uncaught promise rejection caught by base hander'); // see prior test
t.end();
}, 10);
});
// test('bluebirdify onuncaught, no handler - manual confirm output (@TODO, capture stdout)', function(t) {
// var err = new Error('testError - bluebirdify onuncaught');
// err.subProp = { subSubProp: [1, 2 , 3]};
// Promise.reject(err);
// });