2 QUnit
.module( 'mediawiki.errorLogger', QUnit
.newMwEnvironment() );
4 QUnit
.test( 'installGlobalHandler', 7, function ( assert
) {
7 errorUrl
= 'http://example.com',
10 errorObject
= new Error( 'Foo' ),
11 oldHandler
= this.sandbox
.stub();
13 this.sandbox
.stub( mw
, 'track' );
15 mw
.errorLogger
.installGlobalHandler( w
);
17 assert
.ok( w
.onerror
, 'Global handler has been installed' );
18 assert
.strictEqual( w
.onerror( errorMessage
, errorUrl
, errorLine
), false,
19 'Global handler returns false when there is no previous handler' );
20 sinon
.assert
.calledWithExactly( mw
.track
, 'global.error',
21 sinon
.match( { errorMessage
: errorMessage
, url
: errorUrl
, lineNumber
: errorLine
} ) );
24 w
.onerror( errorMessage
, errorUrl
, errorLine
, errorColumn
, errorObject
);
25 sinon
.assert
.calledWithExactly( mw
.track
, 'global.error',
26 sinon
.match( { errorMessage
: errorMessage
, url
: errorUrl
, lineNumber
: errorLine
,
27 columnNumber
: errorColumn
, errorObject
: errorObject
} ) );
29 w
= { onerror
: oldHandler
};
31 mw
.errorLogger
.installGlobalHandler( w
);
32 w
.onerror( errorMessage
, errorUrl
, errorLine
);
33 sinon
.assert
.calledWithExactly( oldHandler
, errorMessage
, errorUrl
, errorLine
);
35 oldHandler
.returns( false );
36 assert
.strictEqual( w
.onerror( errorMessage
, errorUrl
, errorLine
), false,
37 'Global handler preserves false return from previous handler' );
38 oldHandler
.returns( true );
39 assert
.strictEqual( w
.onerror( errorMessage
, errorUrl
, errorLine
), true,
40 'Global handler preserves true return from previous handler' );
42 }( jQuery
, mediaWiki
) );