Skip to content

Commit 7547052

Browse files
$.fn.ready: ensuring the callback is called asynchronously and errors are not silenced
1 parent d28a990 commit 7547052

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/events/ready.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface Cash {
88

99
fn.ready = function ( this: Cash, callback: ( $: typeof cash ) => any ) {
1010

11-
const cb = () => attempt ( callback, cash );
11+
const cb = () => setTimeout ( callback, 0, cash );
1212

1313
if ( doc.readyState !== 'loading' ) {
1414

test/modules/events.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ describe ( 'Events', { beforeEach: getFixtureInit ( fixture ) }, function () {
586586

587587
$(handler);
588588

589+
assert.is ( count, 0 ); // Ensuring it's called asynchronously
590+
589591
setTimeout ( function () {
590592
assert.is ( count, 1 );
591593
assert.is ( arg, $ );
@@ -611,6 +613,9 @@ describe ( 'Events', { beforeEach: getFixtureInit ( fixture ) }, function () {
611613
};
612614

613615
$(handler);
616+
617+
assert.is ( count, 0 ); // Ensuring it's called asynchronously
618+
614619
$(document).trigger ( 'DOMContentLoaded' );
615620

616621
setTimeout ( function () {
@@ -621,12 +626,18 @@ describe ( 'Events', { beforeEach: getFixtureInit ( fixture ) }, function () {
621626

622627
});
623628

624-
QUnit.test ( 'exceptions aren\'t propagated', function ( assert ) { // For some reason we can't use our nice helpers for async assertions :(
629+
QUnit.test ( 'exceptions are propagated', function ( assert ) { // For some reason we can't use our nice helpers for async assertions :(
630+
631+
assert.expect ( 2 );
625632

626633
var done = assert.async ();
627634

635+
window.onerror = function ( err ) {
636+
assert.ok ( /foo/i.test ( err ) );
637+
};
638+
628639
var handler = function () {
629-
throw new Error ();
640+
throw new Error ( 'foo' );
630641
};
631642

632643
$(handler);

0 commit comments

Comments
 (0)