|
@@ -244,24 +244,37 @@ describe( 'Watchdog', () => {
|
|
|
const editorErrorSpy = sinon.spy();
|
|
const editorErrorSpy = sinon.spy();
|
|
|
watchdog.on( 'error', editorErrorSpy );
|
|
watchdog.on( 'error', editorErrorSpy );
|
|
|
|
|
|
|
|
|
|
+ const watchdogErrorHandlerSpy = sinon.spy( watchdog, '_handleError' );
|
|
|
|
|
+
|
|
|
// sinon.stub( window, 'onerror' ).value( undefined ); and similar do not work.
|
|
// sinon.stub( window, 'onerror' ).value( undefined ); and similar do not work.
|
|
|
const originalErrorHandler = window.onerror;
|
|
const originalErrorHandler = window.onerror;
|
|
|
window.onerror = undefined;
|
|
window.onerror = undefined;
|
|
|
|
|
|
|
|
return watchdog.create( element ).then( () => {
|
|
return watchdog.create( element ).then( () => {
|
|
|
|
|
+ const error = new Error( 'foo' );
|
|
|
|
|
+
|
|
|
setTimeout( () => {
|
|
setTimeout( () => {
|
|
|
- throw new Error( 'foo' );
|
|
|
|
|
|
|
+ throw error;
|
|
|
} );
|
|
} );
|
|
|
|
|
+
|
|
|
setTimeout( () => {
|
|
setTimeout( () => {
|
|
|
throw 'bar';
|
|
throw 'bar';
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ setTimeout( () => {
|
|
|
|
|
+ throw null;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
return new Promise( res => {
|
|
return new Promise( res => {
|
|
|
setTimeout( () => {
|
|
setTimeout( () => {
|
|
|
window.onerror = originalErrorHandler;
|
|
window.onerror = originalErrorHandler;
|
|
|
|
|
|
|
|
sinon.assert.notCalled( editorErrorSpy );
|
|
sinon.assert.notCalled( editorErrorSpy );
|
|
|
|
|
|
|
|
|
|
+ // Assert that only instances of the `Error` class will be checked deeper.
|
|
|
|
|
+ sinon.assert.calledOnce( watchdogErrorHandlerSpy );
|
|
|
|
|
+ expect( watchdogErrorHandlerSpy.getCall( 0 ).args[ 0 ] ).to.equal( error );
|
|
|
|
|
+
|
|
|
watchdog.destroy().then( res );
|
|
watchdog.destroy().then( res );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|