Skip to content

Commit f71e32d

Browse files
mr21mgol
authored andcommitted
Effects: Finish should call progress
(cherry-picked from 3dd3d13) Fixes gh-2283 Closes gh-2292
1 parent dc76dca commit f71e32d

File tree

7 files changed

+100
-4
lines changed

7 files changed

+100
-4
lines changed

Gruntfile.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ module.exports = function( grunt ) {
7575
"qunit/qunit.css": "qunitjs/qunit/qunit.css",
7676
"qunit/LICENSE.txt": "qunitjs/LICENSE.txt",
7777

78+
"qunit-assert-step/qunit-assert-step.js":
79+
"qunit-assert-step/qunit-assert-step.js",
80+
"qunit-assert-step/MIT-LICENSE.txt":
81+
"qunit-assert-step/MIT-LICENSE.txt",
82+
7883
"requirejs/require.js": "requirejs/require.js",
7984

8085
"sinon/fake_timers.js": "sinon/lib/sinon/util/fake_timers.js",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright jQuery Foundation and other contributors
2+
http://jquery.com/
3+
4+
Permission is hereby granted, free of charge, to any person obtaining
5+
a copy of this software and associated documentation files (the
6+
"Software"), to deal in the Software without restriction, including
7+
without limitation the rights to use, copy, modify, merge, publish,
8+
distribute, sublicense, and/or sell copies of the Software, and to
9+
permit persons to whom the Software is furnished to do so, subject to
10+
the following conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
QUnit.extend( QUnit.assert, {
2+
3+
/**
4+
* Check the sequence/order
5+
*
6+
* @example test('Example unit test', function(assert) { assert.step(1); setTimeout(function () { assert.step(3); start(); }, 100); assert.step(2); stop(); });
7+
* @param Number expected The excepted step within the test()
8+
* @param String message (optional)
9+
*/
10+
step: function (expected, message) {
11+
// increment internal step counter.
12+
QUnit.config.current.step++;
13+
if (typeof message === "undefined") {
14+
message = "step " + expected;
15+
}
16+
var actual = QUnit.config.current.step;
17+
QUnit.push(QUnit.equiv(actual, expected), actual, expected, message);
18+
}
19+
});
20+
21+
/**
22+
* Reset the step counter for every test()
23+
*/
24+
QUnit.testStart(function () {
25+
QUnit.config.current.step = 0;
26+
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"promises-aplus-tests": "2.1.0",
4545
"q": "1.1.2",
4646
"qunitjs": "1.17.1",
47+
"qunit-assert-step": "1.0.3",
4748
"requirejs": "2.1.17",
4849
"sinon": "1.12.2",
4950
"sizzle": "2.2.0",

src/effects.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ function Animation( elem, properties, options ) {
346346
// resolve when we played the last frame
347347
// otherwise, reject
348348
if ( gotoEnd ) {
349+
deferred.notifyWith( elem, [ animation, 1, 0 ] );
349350
deferred.resolveWith( elem, [ animation, gotoEnd ] );
350351
} else {
351352
deferred.rejectWith( elem, [ animation, gotoEnd ] );

test/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<script src="data/jquery-1.9.1.js"></script>
1414

1515
<script src="../external/qunit/qunit.js"></script>
16+
<script src="../external/qunit-assert-step/qunit-assert-step.js"></script>
1617
<script src="../external/sinon/sinon-1.14.1.js"></script>
1718
<script src="../external/sinon/timers_ie.js"></script>
1819
<script src="../external/npo/npo.js"></script>

test/unit/effects.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,10 +1849,11 @@ QUnit.test( "non-px animation handles non-numeric start (#11971)", function( ass
18491849
this.clock.tick( 10 );
18501850
} );
18511851

1852-
QUnit.test( "Animation callbacks (#11797)", function( assert ) {
1853-
assert.expect( 15 );
1852+
QUnit.test("Animation callbacks (#11797)", function( assert ) {
1853+
assert.expect( 16 );
18541854

1855-
var targets = jQuery( "#foo" ).children(),
1855+
var prog = 0,
1856+
targets = jQuery( "#foo" ).children(),
18561857
done = false,
18571858
expectedProgress = 0;
18581859

@@ -1862,7 +1863,8 @@ QUnit.test( "Animation callbacks (#11797)", function( assert ) {
18621863
assert.ok( true, "empty: start" );
18631864
},
18641865
progress: function( anim, percent ) {
1865-
assert.equal( percent, 0, "empty: progress 0" );
1866+
assert.equal( percent, prog, "empty: progress " + prog );
1867+
prog = 1;
18661868
},
18671869
done: function() {
18681870
assert.ok( true, "empty: done" );
@@ -1934,6 +1936,45 @@ QUnit.test( "Animation callbacks (#11797)", function( assert ) {
19341936
this.clock.tick( 10 );
19351937
} );
19361938

1939+
QUnit.test( "Animation callbacks in order (#2292)", function( assert ) {
1940+
assert.expect( 9 );
1941+
1942+
var step = 0,
1943+
dur = 50;
1944+
1945+
// assert? -> github.com/JamesMGreene/qunit-assert-step
1946+
jQuery( "#foo" ).animate( {
1947+
width: "5px"
1948+
}, {
1949+
duration: dur,
1950+
start: function() {
1951+
assert.step( 1 );
1952+
},
1953+
progress: function( anim, p, ms ) {
1954+
if ( !( step++ ) ) {
1955+
assert.step( 2 );
1956+
assert.strictEqual( p, 0, "first progress callback: progress ratio" );
1957+
assert.strictEqual( ms, dur, "first progress callback: remaining ms" );
1958+
} else {
1959+
assert.step( 3 );
1960+
assert.strictEqual( p, 1, "last progress callback: progress ratio" );
1961+
assert.strictEqual( ms, 0, "last progress callback: remaining ms" );
1962+
}
1963+
},
1964+
done: function() {
1965+
assert.step( 4 );
1966+
},
1967+
fail: function() {
1968+
assert.ok( false, "Animation failed" );
1969+
},
1970+
always: function() {
1971+
assert.step( 5 );
1972+
}
1973+
}).finish();
1974+
1975+
this.clock.tick( dur + 10 );
1976+
} );
1977+
19371978
QUnit.test( "Animate properly sets overflow hidden when animating width/height (#12117)", function( assert ) {
19381979
assert.expect( 8 );
19391980

0 commit comments

Comments
 (0)