mirror of
https://github.com/jquery/jquery.git
synced 2026-04-20 03:01:22 -04:00
Core: Re-throw errors that happened in callbacks wrapped in jQuery ready
Also, expose jQuery.readyException that allows to overwrite the default ready error handler. Fixes gh-3174 Closes gh-3210
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
QUnit.module( "core", { teardown: moduleTeardown } );
|
||||
QUnit.module( "core", {
|
||||
setup: function() {
|
||||
this.sandbox = sinon.sandbox.create();
|
||||
},
|
||||
teardown: function() {
|
||||
this.sandbox.restore();
|
||||
return moduleTeardown.apply( this, arguments );
|
||||
}
|
||||
} );
|
||||
|
||||
QUnit.test( "Basic requirements", function( assert ) {
|
||||
assert.expect( 7 );
|
||||
@@ -1709,3 +1717,45 @@ QUnit.test( "Iterability of jQuery objects (gh-1693)", function( assert ) {
|
||||
assert.ok( true, "The browser doesn't support Symbols" );
|
||||
}
|
||||
} );
|
||||
|
||||
QUnit[ jQuery.Deferred ? "test" : "skip" ]( "jQuery.readyException (original)", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
|
||||
var message;
|
||||
|
||||
this.sandbox.stub( window, "setTimeout", function( fn ) {
|
||||
try {
|
||||
fn();
|
||||
} catch ( error ) {
|
||||
message = error.message;
|
||||
}
|
||||
} );
|
||||
|
||||
jQuery( function() {
|
||||
throw new Error( "Error in jQuery ready" );
|
||||
} );
|
||||
assert.strictEqual(
|
||||
message,
|
||||
"Error in jQuery ready",
|
||||
"The error should have been thrown in a timeout"
|
||||
);
|
||||
} );
|
||||
|
||||
QUnit[ jQuery.Deferred ? "test" : "skip" ]( "jQuery.readyException (custom)", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
|
||||
var done = assert.async();
|
||||
|
||||
this.sandbox.stub( jQuery, "readyException", function( error ) {
|
||||
assert.strictEqual(
|
||||
error.message,
|
||||
"Error in jQuery ready",
|
||||
"The custom jQuery.readyException should have been called"
|
||||
);
|
||||
done();
|
||||
} );
|
||||
|
||||
jQuery( function() {
|
||||
throw new Error( "Error in jQuery ready" );
|
||||
} );
|
||||
} );
|
||||
|
||||
Reference in New Issue
Block a user