Skip to content

Commit

Permalink
HTML Reporter: Ensure unhandled rejection fails.
Browse files Browse the repository at this point in the history
Brings unhandled rejections in line with unhandled exceptions.
  • Loading branch information
rwjblue committed Dec 18, 2017
1 parent 336b32e commit 6249803
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions reporter/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,4 +979,9 @@ export function escapeText( s ) {

return ret;
};

// Listen for unhandled rejections, and call QUnit.onError.
window.addEventListener( "unhandledrejection", function( event ) {
QUnit.onError( event.reason );
} );
}() );
1 change: 1 addition & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<script src="setTimeout.js"></script>
<script src="reporter-html/reporter-html.js"></script>
<script src="reporter-html/diff.js"></script>
<script src="reporter-html/unhandled-rejection.js"></script>
<script src="onerror/inside-test.js"></script>
<script src="onerror/outside-test.js"></script>
</head>
Expand Down
35 changes: 35 additions & 0 deletions test/reporter-html/unhandled-rejection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Currently (2017-12-18) only Chrome has implemented `unhandledRejection`
const IS_CHROME = !!window.chrome;

QUnit.module( "Unhandled Rejections", function( hooks ) {
var originalQUnitOnError;

hooks.beforeEach( function() {
originalQUnitOnError = QUnit.onError;
} );

hooks.afterEach( function() {
QUnit.onError = originalQUnitOnError;
} );

if ( IS_CHROME ) {
QUnit.test( "test passes just fine, but has a rejected promise", function( assert ) {

QUnit.onError = function() {
assert.ok( true, "QUnit.onError was called" );
};

const done = assert.async();

new Promise( function( resolve ) {
setTimeout( resolve );
} )
.then( function() {
throw new Error( "Error thrown in non-returned promise!" );
} );

// prevent test from exiting before unhandled rejection fires
setTimeout( done, 10 );
} );
}
} );

0 comments on commit 6249803

Please sign in to comment.