-
Notifications
You must be signed in to change notification settings - Fork 785
/
unhandled-rejection.js
34 lines (28 loc) 路 1.04 KB
/
unhandled-rejection.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
"use strict";
QUnit.module( "Unhandled Rejections", function() {
QUnit.test( "test passes just fine, but has a rejected promise", function( assert ) {
assert.ok( true );
const done = assert.async();
new Promise( function( resolve ) {
setTimeout( resolve );
} )
.then( function() {
// throwing a non-Error here because stack trace representation
// across Node versions is not stable (they continue to get better)
throw {
message: "Error thrown in non-returned promise!",
stack: `Error: Error thrown in non-returned promise!
at /some/path/wherever/unhandled-rejection.js:13:11`
};
} );
// prevent test from exiting before unhandled rejection fires
setTimeout( done, 10 );
} );
// rejecting with a non-Error here because stack trace representation
// across Node versions is not stable (they continue to get better)
Promise.reject( {
message: "outside of a test context",
stack: `Error: outside of a test context
at Object.<anonymous> (/some/path/wherever/unhandled-rejection.js:20:18)`
} );
} );