Skip to content

Commit

Permalink
Tests: Use mock Promise in test.each() test cases
Browse files Browse the repository at this point in the history
These tests were enabled in 47576c1, but then started failing
the IE9 browser test, as it does not have native a Promise (and we don't
polyfill it globally so as to ensure QUnit internally can't accidentally
rely on it).

Ref 3e55dd67a4aa7b6202c0844c6.
Ref #1569.
  • Loading branch information
Krinkle committed Jun 6, 2021
1 parent 835b7c1 commit 9f2f448
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
10 changes: 2 additions & 8 deletions test/main/each.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
} );
Expand All @@ -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 ) {
Expand Down
31 changes: 31 additions & 0 deletions test/main/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
} );
} );

0 comments on commit 9f2f448

Please sign in to comment.