Skip to content

Commit 5c01cb1

Browse files
committed
Tests: Fix Deferred tests in Android 5.0's stock Chrome browser & Yandex.Browser
Some Chrome versions newer than 30 but older than 42 display the "undefined is not a function" error, not mentioning the function name. This has been fixed in Chrome 42. Relax two tests to allow for this divergence in older Chromoiums. This affects our Android 5.0 & Yandex.Browser testing.
1 parent 250fd80 commit 5c01cb1

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

test/unit/deferred.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,14 +534,32 @@ QUnit[ window.console ? "test" : "skip" ]( "jQuery.Deferred.exceptionHook", func
534534
oldWarn = window.console.warn;
535535

536536
window.console.warn = function( msg ) {
537-
assert.ok( /barf/.test( msg ), "Message: " + msg );
537+
538+
// Support: Chrome < 42
539+
// Some Chrome versions newer than 30 but older than 42 display the "undefined is
540+
// not a function" error, not mentioning the function name. This has been fixed
541+
// in Chrome 42. Relax this test there.
542+
// This affects our Android 5.0 & Yandex.Browser testing.
543+
var oldChromium = false;
544+
if ( /chrome/i.test( navigator.userAgent ) ) {
545+
oldChromium = parseInt(
546+
navigator.userAgent.match( /chrome\/(\d+)/i )[ 1 ], 10 ) < 42;
547+
}
548+
if ( oldChromium ) {
549+
assert.ok( /(?:barf|undefined)/.test( msg ), "Message: " + msg );
550+
} else {
551+
assert.ok( /barf/.test( msg ), "Message: " + msg );
552+
}
538553
};
539554
jQuery.when(
540555
defer.then( function() {
556+
541557
// Should get an error
542558
jQuery.barf();
543559
} ).then( null, jQuery.noop ),
560+
544561
defer.then( function() {
562+
545563
// Should NOT get an error
546564
throw new Error( "Make me a sandwich" );
547565
} ).then( null, jQuery.noop )
@@ -562,6 +580,7 @@ QUnit[ window.console ? "test" : "skip" ]( "jQuery.Deferred.exceptionHook with s
562580
oldWarn = window.console.warn;
563581

564582
jQuery.Deferred.getStackHook = function() {
583+
565584
// Default exceptionHook assumes the stack is in a form console.warn can log,
566585
// but a custom getStackHook+exceptionHook pair could save a raw form and
567586
// format it to a string only when an exception actually occurs.
@@ -570,7 +589,22 @@ QUnit[ window.console ? "test" : "skip" ]( "jQuery.Deferred.exceptionHook with s
570589
};
571590

572591
window.console.warn = function( msg, stack ) {
573-
assert.ok( /cough_up_hairball/.test( msg ), "Function mentioned: " + msg );
592+
593+
// Support: Chrome < 42
594+
// Some Chrome versions newer than 30 but older than 42 display the "undefined is
595+
// not a function" error, not mentioning the function name. This has been fixed
596+
// in Chrome 42. Relax this test there.
597+
// This affects our Android 5.0 & Yandex.Browser testing.
598+
var oldChromium = false;
599+
if ( /chrome/i.test( navigator.userAgent ) ) {
600+
oldChromium = parseInt(
601+
navigator.userAgent.match( /chrome\/(\d+)/i )[ 1 ], 10 ) < 42;
602+
}
603+
if ( oldChromium ) {
604+
assert.ok( /(?:cough_up_hairball|undefined)/.test( msg ), "Function mentioned: " + msg );
605+
} else {
606+
assert.ok( /cough_up_hairball/.test( msg ), "Function mentioned: " + msg );
607+
}
574608
assert.ok( /NO STACK FOR YOU/.test( stack ), "Stack trace included: " + stack );
575609
};
576610
defer.then( function() {

0 commit comments

Comments
 (0)