Skip to content

Commit 3dd3d13

Browse files
mr21mgol
authored andcommitted
Effects: Finish should call progress
Fixes jquerygh-2283 Closes jquerygh-2292
1 parent 98cee73 commit 3dd3d13

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
@@ -78,6 +78,11 @@ module.exports = function( grunt ) {
7878
"qunit/qunit.css": "qunitjs/qunit/qunit.css",
7979
"qunit/LICENSE.txt": "qunitjs/LICENSE.txt",
8080

81+
"qunit-assert-step/qunit-assert-step.js":
82+
"qunit-assert-step/qunit-assert-step.js",
83+
"qunit-assert-step/MIT-LICENSE.txt":
84+
"qunit-assert-step/MIT-LICENSE.txt",
85+
8186
"requirejs/require.js": "requirejs/require.js",
8287

8388
"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.10.3",
4950
"sizzle": "2.2.0",

src/effects.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ function Animation( elem, properties, options ) {
345345

346346
// Resolve when we played the last frame; otherwise, reject
347347
if ( gotoEnd ) {
348+
deferred.notifyWith( elem, [ animation, 1, 0 ] );
348349
deferred.resolveWith( elem, [ animation, gotoEnd ] );
349350
} else {
350351
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/npo/npo.js"></script>
1819
<script src="../external/requirejs/require.js"></script>

test/unit/effects.js

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

1835-
QUnit.test( "Animation callbacks (#11797)", function( assert ) {
1836-
assert.expect( 15 );
1835+
QUnit.test("Animation callbacks (#11797)", function( assert ) {
1836+
assert.expect( 16 );
18371837

1838-
var targets = jQuery( "#foo" ).children(),
1838+
var prog = 0,
1839+
targets = jQuery( "#foo" ).children(),
18391840
done = false,
18401841
expectedProgress = 0;
18411842

@@ -1845,7 +1846,8 @@ QUnit.test( "Animation callbacks (#11797)", function( assert ) {
18451846
assert.ok( true, "empty: start" );
18461847
},
18471848
progress: function( anim, percent ) {
1848-
assert.equal( percent, 0, "empty: progress 0" );
1849+
assert.equal( percent, prog, "empty: progress " + prog );
1850+
prog = 1;
18491851
},
18501852
done: function() {
18511853
assert.ok( true, "empty: done" );
@@ -1917,6 +1919,45 @@ QUnit.test( "Animation callbacks (#11797)", function( assert ) {
19171919
this.clock.tick( 10 );
19181920
} );
19191921

1922+
QUnit.test( "Animation callbacks in order (#2292)", function( assert ) {
1923+
assert.expect( 9 );
1924+
1925+
var step = 0,
1926+
dur = 50;
1927+
1928+
// assert? -> github.com/JamesMGreene/qunit-assert-step
1929+
jQuery( "#foo" ).animate( {
1930+
width: "5px"
1931+
}, {
1932+
duration: dur,
1933+
start: function() {
1934+
assert.step( 1 );
1935+
},
1936+
progress: function( anim, p, ms ) {
1937+
if ( !( step++ ) ) {
1938+
assert.step( 2 );
1939+
assert.strictEqual( p, 0, "first progress callback: progress ratio" );
1940+
assert.strictEqual( ms, dur, "first progress callback: remaining ms" );
1941+
} else {
1942+
assert.step( 3 );
1943+
assert.strictEqual( p, 1, "last progress callback: progress ratio" );
1944+
assert.strictEqual( ms, 0, "last progress callback: remaining ms" );
1945+
}
1946+
},
1947+
done: function() {
1948+
assert.step( 4 );
1949+
},
1950+
fail: function() {
1951+
assert.ok( false, "Animation failed" );
1952+
},
1953+
always: function() {
1954+
assert.step( 5 );
1955+
}
1956+
}).finish();
1957+
1958+
this.clock.tick( dur + 10 );
1959+
} );
1960+
19201961
QUnit.test( "Animate properly sets overflow hidden when animating width/height (#12117)", function( assert ) {
19211962
assert.expect( 8 );
19221963

0 commit comments

Comments
 (0)