From b40a0f12e7403156b0a40fdd36b8e4eac36caf0a Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sun, 6 Jun 2021 17:35:00 +0100 Subject: [PATCH] Tests: Use mock Promise in test.each() tests to fix IE9 build These tests were enabled in 47576c16f4b19f7, but then started failing the IE9 browser test, as it does not have native a Promise. We don't polyfill this globally to ensure that QUnit will not accidentally rely on it internally. Ref 3e55dd67a4aa7b6202c0844c6. Ref https://github.com/qunitjs/qunit/pull/1569. --- test/main/each.js | 10 ++-------- test/main/promise.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/test/main/each.js b/test/main/each.js index c8a3f8daf..e829bce7a 100644 --- a/test/main/each.js +++ b/test/main/each.js @@ -2,14 +2,6 @@ QUnit.module( "test.each", function() { QUnit.test.each( "test.each", [ [ 1, 2, 3 ], [ 1, 1, 2 ] ], function( assert, data ) { assert.strictEqual( data[ 0 ] + data[ 1 ], data[ 2 ] ); } ); - QUnit.test.each( "test.each returning a Promise", [ [ 1, 2, 3 ], [ 1, 1, 2 ] ], function( assert, data ) { - function sum( a, b ) { - return new Promise( function( resolve ) { - resolve( a + b ); - } ); - } - return sum( data[ 0 ], data[ 1 ] ).then( function( result ) { assert.strictEqual( result, data[ 2 ] ); } ); - } ); QUnit.test.each( "test.each 1D", [ 1, [], "some" ], function( assert, value ) { assert.true( Boolean( value ) ); } ); @@ -22,6 +14,8 @@ QUnit.module( "test.each", function() { } ); } ); + // Promise support for test.each() is tested in test/main/promise.js. + QUnit.module( "arguments", function( hooks ) { var todoArgs; hooks.after( function( assert ) { diff --git a/test/main/promise.js b/test/main/promise.js index fc2527327..33c2c4ce3 100644 --- a/test/main/promise.js +++ b/test/main/promise.js @@ -216,4 +216,35 @@ QUnit.module( "Support for Promise", function() { return createMockPromise( assert, true, "this is an error" ); } ); + + QUnit.module( "test.each()", { + afterEach: function( assert ) { + + // Restore + if ( this.pushFailure ) { + assert.test.pushFailure = this.pushFailure; + } + } + } ); + + QUnit.test.each( "fulfilled Promise", [ 1 ], function( assert, _data ) { + assert.expect( 1 ); + + // Adds 1 assertion + return createMockPromise( assert ); + } ); + + QUnit.test.each( "rejected Promise with Error", [ 1 ], function( assert, _data ) { + assert.expect( 2 ); + + this.pushFailure = assert.test.pushFailure; + assert.test.pushFailure = function( message ) { + assert.strictEqual( + message, + "Promise rejected during \"rejected Promise with Error [0]\": this is an error" + ); + }; + + return createMockPromise( assert, true, new Error( "this is an error" ) ); + } ); } );