]> source.dussan.org Git - jquery.git/commitdiff
Effects: Finish should call progress
authorThomas Tortorini <thomastortorini@gmail.com>
Sun, 10 May 2015 23:39:26 +0000 (01:39 +0200)
committerMichał Gołębiowski <m.goleb@gmail.com>
Tue, 8 Sep 2015 00:40:54 +0000 (02:40 +0200)
Fixes gh-2283
Closes gh-2292

Gruntfile.js
external/qunit-assert-step/MIT-LICENSE.txt [new file with mode: 0644]
external/qunit-assert-step/qunit-assert-step.js [new file with mode: 0644]
package.json
src/effects.js
test/index.html
test/unit/effects.js

index 50a662cbaf986a350c1159f87966086587fb7c8c..c05b4254643a06bcb31eb166de7ec5ceb1bc729c 100644 (file)
@@ -78,6 +78,11 @@ module.exports = function( grunt ) {
                                        "qunit/qunit.css": "qunitjs/qunit/qunit.css",
                                        "qunit/LICENSE.txt": "qunitjs/LICENSE.txt",
 
+                                       "qunit-assert-step/qunit-assert-step.js":
+                                       "qunit-assert-step/qunit-assert-step.js",
+                                       "qunit-assert-step/MIT-LICENSE.txt":
+                                       "qunit-assert-step/MIT-LICENSE.txt",
+
                                        "requirejs/require.js": "requirejs/require.js",
 
                                        "sinon/fake_timers.js": "sinon/lib/sinon/util/fake_timers.js",
diff --git a/external/qunit-assert-step/MIT-LICENSE.txt b/external/qunit-assert-step/MIT-LICENSE.txt
new file mode 100644 (file)
index 0000000..aed5dc9
--- /dev/null
@@ -0,0 +1,21 @@
+Copyright jQuery Foundation and other contributors
+http://jquery.com/
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/external/qunit-assert-step/qunit-assert-step.js b/external/qunit-assert-step/qunit-assert-step.js
new file mode 100644 (file)
index 0000000..90bca18
--- /dev/null
@@ -0,0 +1,26 @@
+QUnit.extend( QUnit.assert, {
+
+       /**
+        * Check the sequence/order
+        *
+        * @example test('Example unit test', function(assert) { assert.step(1); setTimeout(function () { assert.step(3); start(); }, 100); assert.step(2); stop(); });
+        * @param Number expected The excepted step within the test()
+        * @param String message (optional)
+        */
+       step: function (expected, message) {
+               // increment internal step counter.
+               QUnit.config.current.step++;
+               if (typeof message === "undefined") {
+                       message = "step " + expected;
+               }
+               var actual = QUnit.config.current.step;
+               QUnit.push(QUnit.equiv(actual, expected), actual, expected, message);
+       }
+});
+
+/**
+ * Reset the step counter for every test()
+ */
+QUnit.testStart(function () {
+       QUnit.config.current.step = 0;
+});
index b78f11a13a70e3e20c2bad4b92839d204ef7dc45..27ca0757f07033db49d3ea0caaa3aacf338d240d 100644 (file)
@@ -44,6 +44,7 @@
     "promises-aplus-tests": "2.1.0",
     "q": "1.1.2",
     "qunitjs": "1.17.1",
+    "qunit-assert-step": "1.0.3",
     "requirejs": "2.1.17",
     "sinon": "1.10.3",
     "sizzle": "2.2.0",
index 90ac4b1e66cd67cb6d84f29177eea2d7e96951d4..64f9353eff2290a54afcab23fa68778718447fd9 100644 (file)
@@ -345,6 +345,7 @@ function Animation( elem, properties, options ) {
 
                                // Resolve when we played the last frame; otherwise, reject
                                if ( gotoEnd ) {
+                                       deferred.notifyWith( elem, [ animation, 1, 0 ] );
                                        deferred.resolveWith( elem, [ animation, gotoEnd ] );
                                } else {
                                        deferred.rejectWith( elem, [ animation, gotoEnd ] );
index 0285176d3d662ceffd9ae5fcdc54b083545d4edc..54a1ee041e14e207a1a109b272518fdcdfba7687 100644 (file)
@@ -13,6 +13,7 @@
        <script src="data/jquery-1.9.1.js"></script>
 
        <script src="../external/qunit/qunit.js"></script>
+       <script src="../external/qunit-assert-step/qunit-assert-step.js"></script>
        <script src="../external/sinon/sinon-1.14.1.js"></script>
        <script src="../external/npo/npo.js"></script>
        <script src="../external/requirejs/require.js"></script>
index 755b074f84b8e01c78784e577f20ed256eae90a5..4d51adbc9a210bad178167b9c0712368caaf1d7a 100644 (file)
@@ -1832,10 +1832,11 @@ QUnit.test( "non-px animation handles non-numeric start (#11971)", function( ass
        this.clock.tick( 10 );
 } );
 
-QUnit.test( "Animation callbacks (#11797)", function( assert ) {
-       assert.expect( 15 );
+QUnit.test("Animation callbacks (#11797)", function( assert ) {
+       assert.expect( 16 );
 
-       var targets = jQuery( "#foo" ).children(),
+       var prog = 0,
+               targets = jQuery( "#foo" ).children(),
                done = false,
                expectedProgress = 0;
 
@@ -1845,7 +1846,8 @@ QUnit.test( "Animation callbacks (#11797)", function( assert ) {
                        assert.ok( true, "empty: start" );
                },
                progress: function( anim, percent ) {
-                       assert.equal( percent, 0, "empty: progress 0" );
+                       assert.equal( percent, prog, "empty: progress " + prog );
+                       prog = 1;
                },
                done: function() {
                        assert.ok( true, "empty: done" );
@@ -1917,6 +1919,45 @@ QUnit.test( "Animation callbacks (#11797)", function( assert ) {
        this.clock.tick( 10 );
 } );
 
+QUnit.test( "Animation callbacks in order (#2292)", function( assert ) {
+       assert.expect( 9 );
+
+       var step = 0,
+               dur = 50;
+
+       // assert? -> github.com/JamesMGreene/qunit-assert-step
+       jQuery( "#foo" ).animate( {
+               width: "5px"
+       }, {
+               duration: dur,
+               start: function() {
+                       assert.step( 1 );
+               },
+               progress: function( anim, p, ms ) {
+                       if ( !( step++ ) ) {
+                               assert.step( 2 );
+                               assert.strictEqual( p, 0, "first progress callback: progress ratio" );
+                               assert.strictEqual( ms, dur, "first progress callback: remaining ms" );
+                       } else {
+                               assert.step( 3 );
+                               assert.strictEqual( p, 1, "last progress callback: progress ratio" );
+                               assert.strictEqual( ms, 0, "last progress callback: remaining ms" );
+                       }
+               },
+               done: function() {
+                       assert.step( 4 );
+               },
+               fail: function() {
+                       assert.ok( false, "Animation failed" );
+               },
+               always: function() {
+                       assert.step( 5 );
+               }
+       }).finish();
+
+       this.clock.tick( dur + 10 );
+} );
+
 QUnit.test( "Animate properly sets overflow hidden when animating width/height (#12117)", function( assert ) {
        assert.expect( 8 );