|
| 1 | +"use strict"; |
1 | 2 |
|
2 | | -QUnit.test( "Sanity", function( assert ) { |
| 3 | +// Polyfill `globalThis` for legacy browsers. |
| 4 | +if ( typeof globalThis === "undefined" ) { |
| 5 | + window.globalThis = window; |
| 6 | +} |
| 7 | + |
| 8 | +QUnit.test( "Environment check", function( assert ) { |
3 | 9 | assert.expect( 1 ); |
4 | | - assert.ok( Array.prototype.push, "Array.push()" ); |
| 10 | + assert.ok( Array.prototype.push, "Array#push()" ); |
5 | 11 | } ); |
6 | 12 |
|
7 | | -QUnit[ window.console ? "test" : "skip" ]( |
| 13 | +QUnit[ globalThis.console ? "test" : "skip" ]( |
8 | 14 | "jQuery.Deferred.exceptionHook", |
9 | 15 | function exceptionHookTest( assert ) { |
10 | 16 |
|
11 | 17 | assert.expect( 1 ); |
12 | 18 |
|
13 | 19 | var done = assert.async(), |
14 | 20 | defer = jQuery.Deferred(), |
15 | | - oldWarn = window.console.warn; |
| 21 | + oldWarn = globalThis.console.warn; |
| 22 | + |
| 23 | + if ( jQuery.fn.jquery.indexOf( "3." ) === 0 ) { |
| 24 | + globalThis.console.warn = function( msg ) { |
| 25 | + assert.ok( /barf/.test( msg ), "Message: " + msg ); |
| 26 | + }; |
| 27 | + } else { |
| 28 | + globalThis.console.warn = function( _intro, error ) { |
| 29 | + assert.ok( /barf/.test( error.message + "\n" + error.stack ), |
| 30 | + "Error mentions the method: " + error.message + "\n" + error.stack ); |
| 31 | + }; |
| 32 | + } |
16 | 33 |
|
17 | | - window.console.warn = function( msg ) { |
18 | | - assert.ok( /barf/.test( msg ), "Message: " + msg ); |
19 | | - }; |
20 | 34 | jQuery.when( |
21 | 35 | defer.then( function() { |
| 36 | + |
22 | 37 | // Should get an error |
23 | 38 | jQuery.barf(); |
24 | 39 | } ).then( null, jQuery.noop ), |
25 | 40 | defer.then( function() { |
| 41 | + |
26 | 42 | // Should NOT get an error |
27 | 43 | throw new Error( "Make me a sandwich" ); |
28 | 44 | } ).then( null, jQuery.noop ) |
29 | 45 | ).then( function( ) { |
30 | | - window.console.warn = oldWarn; |
| 46 | + globalThis.console.warn = oldWarn; |
31 | 47 | done(); |
32 | 48 | } ); |
33 | 49 |
|
34 | 50 | defer.resolve(); |
35 | 51 | } ); |
36 | 52 |
|
37 | | -QUnit[ window.console ? "test" : "skip" ]( |
| 53 | +QUnit[ globalThis.console ? "test" : "skip" ]( |
38 | 54 | "jQuery.Deferred.exceptionHook with stack hooks", |
39 | 55 | function exceptionHookWithStack( assert ) { |
40 | 56 |
|
41 | 57 | assert.expect( 2 ); |
42 | 58 |
|
43 | 59 | var done = assert.async(), |
44 | 60 | defer = jQuery.Deferred(), |
45 | | - oldWarn = window.console.warn; |
| 61 | + oldWarn = globalThis.console.warn; |
| 62 | + |
| 63 | + globalThis.console.warn = function( intro, error, asyncError ) { |
| 64 | + assert.ok( |
| 65 | + /cough_up_hairball/.test( intro + "\n" + ( error && error.message || error ) ), |
| 66 | + "Function mentioned: " + intro + "\n" + ( error && error.message || error ) |
| 67 | + ); |
46 | 68 |
|
47 | | - window.console.warn = function( msg, stack ) { |
48 | | - assert.ok( /cough_up_hairball/.test( msg ), "Function mentioned: " + msg ); |
49 | | - assert.ok( /exceptionHookWithStack/.test( stack ), "Stack trace included: \n" + stack ); |
| 69 | + assert.ok( |
| 70 | + /exceptionHookWithStack/.test( asyncError.message + "\n" + asyncError.stack ), |
| 71 | + "Stack trace included: " + asyncError.message + "\n" + asyncError.stack |
| 72 | + ); |
50 | 73 | }; |
| 74 | + |
51 | 75 | defer.then( function() { |
52 | 76 | jQuery.cough_up_hairball(); |
53 | 77 | } ).then( null, function( ) { |
54 | | - window.console.warn = oldWarn; |
55 | | - delete jQuery.Deferred.getStackHook; |
| 78 | + globalThis.console.warn = oldWarn; |
| 79 | + delete jQuery.Deferred.getErrorHook; |
56 | 80 | done(); |
57 | 81 | } ); |
58 | 82 |
|
|
0 commit comments