aboutsummaryrefslogtreecommitdiffstats
path: root/test/promises_aplus_adapters
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2019-03-04 18:30:51 +0100
committerGitHub <noreply@github.com>2019-03-04 18:30:51 +0100
commit9cb124ed00aad8ac47690e31ad0bb8c3c365663d (patch)
tree4cfbdd63f3dbe87398b8bde41de1f2e65ed3c4f2 /test/promises_aplus_adapters
parentc10945d0e15c5048ae8b5b7e3f8241ad27671a7c (diff)
downloadjquery-9cb124ed00aad8ac47690e31ad0bb8c3c365663d.tar.gz
jquery-9cb124ed00aad8ac47690e31ad0bb8c3c365663d.zip
Build: Update jsdom; migrate a test with Symbol polyfill to an iframe test
So far, we've been testing that jQuery element iteration works with polyfilled Symbol & transpiled for-of via a Node test with jsdom with the Symbol global removed. Unfortunately, jsdom now requires Symbol to be present for its internal functionality so such a test is no longer possible. Instead, it's been migrated to an iframe test with transpiled JavaScript. This PR also enables us to use ECMAScript 2017 or newer in Node.js code. Closes gh-4305
Diffstat (limited to 'test/promises_aplus_adapters')
-rw-r--r--test/promises_aplus_adapters/deferred.js25
-rw-r--r--test/promises_aplus_adapters/when.js78
2 files changed, 48 insertions, 55 deletions
diff --git a/test/promises_aplus_adapters/deferred.js b/test/promises_aplus_adapters/deferred.js
index 31af16655..5e3ffe2d8 100644
--- a/test/promises_aplus_adapters/deferred.js
+++ b/test/promises_aplus_adapters/deferred.js
@@ -1,20 +1,17 @@
"use strict";
-require( "jsdom" ).env( "", function( errors, window ) {
- if ( errors ) {
- console.error( errors );
- return;
- }
+const { JSDOM } = require( "jsdom" );
- var jQuery = require( "../../" )( window );
+const { window } = new JSDOM( "" );
- module.exports.deferred = function() {
- var deferred = jQuery.Deferred();
+const jQuery = require( "../../" )( window );
- return {
- promise: deferred.promise(),
- resolve: deferred.resolve.bind( deferred ),
- reject: deferred.reject.bind( deferred )
- };
+module.exports.deferred = () => {
+ const deferred = jQuery.Deferred();
+
+ return {
+ promise: deferred.promise(),
+ resolve: deferred.resolve.bind( deferred ),
+ reject: deferred.reject.bind( deferred )
};
-} );
+};
diff --git a/test/promises_aplus_adapters/when.js b/test/promises_aplus_adapters/when.js
index adde1a13a..3e945d475 100644
--- a/test/promises_aplus_adapters/when.js
+++ b/test/promises_aplus_adapters/when.js
@@ -1,49 +1,45 @@
"use strict";
-require( "jsdom" ).env( "", function( errors, window ) {
- if ( errors ) {
- console.error( errors );
- return;
- }
+const { JSDOM } = require( "jsdom" );
- var jQuery = require( "../../" )( window );
+const { window } = new JSDOM( "" );
- module.exports.deferred = function() {
- var adopted, promised,
- obj = {
- resolve: function() {
- if ( !adopted ) {
- adopted = jQuery.when.apply( jQuery, arguments );
- if ( promised ) {
- adopted.then( promised.resolve, promised.reject );
- }
- }
- return adopted;
- },
- reject: function( value ) {
- if ( !adopted ) {
- adopted = jQuery.when( jQuery.Deferred().reject( value ) );
- if ( promised ) {
- adopted.then( promised.resolve, promised.reject );
- }
- }
- return adopted;
- },
+const jQuery = require( "../../" )( window );
- // A manually-constructed thenable that works even if calls precede resolve/reject
- promise: {
- then: function() {
- if ( !adopted ) {
- if ( !promised ) {
- promised = jQuery.Deferred();
- }
- return promised.then.apply( promised, arguments );
- }
- return adopted.then.apply( adopted, arguments );
- }
+module.exports.deferred = () => {
+ let adopted, promised;
+
+ return {
+ resolve: function() {
+ if ( !adopted ) {
+ adopted = jQuery.when.apply( jQuery, arguments );
+ if ( promised ) {
+ adopted.then( promised.resolve, promised.reject );
}
- };
+ }
+ return adopted;
+ },
+ reject: function( value ) {
+ if ( !adopted ) {
+ adopted = jQuery.when( jQuery.Deferred().reject( value ) );
+ if ( promised ) {
+ adopted.then( promised.resolve, promised.reject );
+ }
+ }
+ return adopted;
+ },
- return obj;
+ // A manually-constructed thenable that works even if calls precede resolve/reject
+ promise: {
+ then: function() {
+ if ( !adopted ) {
+ if ( !promised ) {
+ promised = jQuery.Deferred();
+ }
+ return promised.then.apply( promised, arguments );
+ }
+ return adopted.then.apply( adopted, arguments );
+ }
+ }
};
-} );
+};