aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichał Gołębiowski <m.goleb@gmail.com>2016-06-29 14:19:04 +0200
committerMichał Gołębiowski <m.goleb@gmail.com>2016-07-07 10:23:06 +0200
commitad6a94c3f1747829082b85fd53ee2efbae879707 (patch)
tree2b532c0d524d7848b70b16be0a7699fe2b42daec /test
parent25d8ccd1112d75394b91071ff7eba13283aaf898 (diff)
downloadjquery-ad6a94c3f1747829082b85fd53ee2efbae879707.tar.gz
jquery-ad6a94c3f1747829082b85fd53ee2efbae879707.zip
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
Diffstat (limited to 'test')
-rw-r--r--test/unit/core.js52
1 files changed, 51 insertions, 1 deletions
diff --git a/test/unit/core.js b/test/unit/core.js
index 8ad3c86ce..8c0f8640e 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -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" );
+ } );
+} );