diff options
author | Oleg Gaidarenko <markelog@gmail.com> | 2016-06-11 10:30:12 +0300 |
---|---|---|
committer | Oleg Gaidarenko <markelog@gmail.com> | 2016-06-11 10:39:51 +0300 |
commit | a4474c9a0025095f82d734a9d7230eace2f08ef8 (patch) | |
tree | e62f988ad38a32e9bb639bb28431f365386b0863 /test/promises_aplus_adapters | |
parent | f80ae67c53c0a4bfc95741ed39d7f9e498eaf02b (diff) | |
download | jquery-a4474c9a0025095f82d734a9d7230eace2f08ef8.tar.gz jquery-a4474c9a0025095f82d734a9d7230eace2f08ef8.zip |
Tests: Move promise/A+ adapters for tests to dedicated folder
Diffstat (limited to 'test/promises_aplus_adapters')
-rw-r--r-- | test/promises_aplus_adapters/.eslintrc | 7 | ||||
-rw-r--r-- | test/promises_aplus_adapters/deferred.js | 20 | ||||
-rw-r--r-- | test/promises_aplus_adapters/when.js | 49 |
3 files changed, 76 insertions, 0 deletions
diff --git a/test/promises_aplus_adapters/.eslintrc b/test/promises_aplus_adapters/.eslintrc new file mode 100644 index 000000000..11368d984 --- /dev/null +++ b/test/promises_aplus_adapters/.eslintrc @@ -0,0 +1,7 @@ +{ + "env": { + "node": true + }, + "extends": "../.eslintrc", + "root": true +} diff --git a/test/promises_aplus_adapters/deferred.js b/test/promises_aplus_adapters/deferred.js new file mode 100644 index 000000000..31af16655 --- /dev/null +++ b/test/promises_aplus_adapters/deferred.js @@ -0,0 +1,20 @@ +"use strict"; + +require( "jsdom" ).env( "", function( errors, window ) { + if ( errors ) { + console.error( errors ); + return; + } + + var jQuery = require( "../../" )( window ); + + module.exports.deferred = function() { + var 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 new file mode 100644 index 000000000..adde1a13a --- /dev/null +++ b/test/promises_aplus_adapters/when.js @@ -0,0 +1,49 @@ +"use strict"; + +require( "jsdom" ).env( "", function( errors, window ) { + if ( errors ) { + console.error( errors ); + return; + } + + var jQuery = require( "../../" )( window ); + + 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; + }, + + // 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 ); + } + } + }; + + return obj; + }; +} ); |