Tests: Add unit tests for callback-only animation signatures#5776
Conversation
|
Thanks for the PR. Before we review it, please sign our CLA. |
mgol
left a comment
There was a problem hiding this comment.
Thanks for the PR! Please read my comments.
|
Oh, and in the commit message & PR description reference gh-1738 instead of |
35b0cad to
b0e9578
Compare
Add tests for show/hide/toggle(callback), slideDown/slideUp/slideToggle(callback), and fadeIn/fadeOut/fadeToggle(callback) to verify that passing only a callback function as the first argument triggers an animated transition with the default duration. These signatures have been supported historically but were never explicitly tested. The callback-only form is documented and should animate with jQuery.fx.speeds._default (400ms) duration rather than toggling visibility immediately. Ref jquerygh-1738 Closes jquerygh-1738
b0e9578 to
a29f145
Compare
mgol
left a comment
There was a problem hiding this comment.
Thanks! We could consider abstracting these three tests since they are almost identical, but 3 tests seem still manageable and debugging is a bit easier, so I'm fine with the way it is.
mgol
left a comment
There was a problem hiding this comment.
Oh, actually, the tests are failing. Please run them locally and request re-review when they pass.
The expected assertion counts were incorrect: - show/hide/toggle test: 12 → 9 (3 groups × 3 assertions) - slideDown/slideUp/slideToggle test: 9 → 6 (3 groups × 2 assertions) - fadeIn/fadeOut/fadeToggle test: 9 → 6 (3 groups × 2 assertions) Ref jquerygh-1738
|
Hi - this has been outstanding for a while now, should still be good. |
mgol
left a comment
There was a problem hiding this comment.
I had a closer look and I've noticed one other issue, see my comment.
Per review feedback, the slideDown/slideUp/slideToggle and fadeIn/fadeOut/fadeToggle callback-only tests now verify the element's visibility state after each animation completes, matching the pattern already used in the show/hide/toggle(callback) test. Ref jquerygh-1738
|
Tests are failing. |
|
Yes - the tests are intentionally demonstrating the bug described in gh-1738. I'll sort out a source fix. |
|
Hmm, I don't see any bug described in gh-1738, can you point me to what you're describing? |
The completion tick needs to account for the animation frame interval (fxInterval = 13ms). A 400ms animation completes at the first 13ms boundary >= 400ms (ceil(400/13) * 13 = 403ms), so ticking only 401ms (_default * 0.2 + 1) falls short. Use _default * 0.2 + fxInterval instead to ensure the animation has completed. Ref jquerygh-1738
|
Ignore me - mixed up with another PR. |
The tests use :hidden/:visible pseudo-selectors which require jQuery's custom selector module. Gate them with QUnit.jQuerySelectors to skip when running the selector-native build variant. Ref jquerygh-1738
|
test:selector-native was failing because :hidden/:visible aren't valid in native selector builds. Now gated with QUnit.jQuerySelectors so tests skip instead of crash. |
Replace :visible/:hidden pseudo-selector assertions with
.css("display") checks so that the callback-only animation tests
run in both the selector and selector-native builds. These are
effects tests, not selector tests, so they should not be gated
behind QUnit.jQuerySelectors.
- :hidden checks now use .css('display') === 'none'
- :visible checks now use .css('display') !== 'none'
- Tests no longer skip in selector-native build
Ref jquerygh-1738
Use strictEqual with the expected "block" value for visible-state assertions rather than the weaker notStrictEqual against "none". All test elements are divs so the computed display after showing is always "block". Ref jquerygh-1738
mgol
left a comment
There was a problem hiding this comment.
Looks good to me, thanks!
I'll leave it open for a while so that other team members have a chance to look at it, but the Easter break is coming, so some delays are possible. I don't expect major hurdles anymore, though.
Add tests for: * show/hide/toggle(callback) * slideDown/slideUp/slideToggle(callback) * fadeIn/fadeOut/fadeToggle(callback) to verify that passing only a callback function as the first argument triggers an animated transition with the default duration. These signatures have been supported historically but were never explicitly tested. The callback-only form is documented and should animate with `jQuery.fx.speeds._default` (400ms) duration rather than toggling visibility immediately. Fixes gh-1738 Closes gh-5776 (cherry picked from commit ac83749)
Add tests for: * show/hide/toggle(callback) * slideDown/slideUp/slideToggle(callback) * fadeIn/fadeOut/fadeToggle(callback) to verify that passing only a callback function as the first argument triggers an animated transition with the default duration. These signatures have been supported historically but were never explicitly tested. The callback-only form is documented and should animate with `jQuery.fx.speeds._default` (400ms) duration rather than toggling visibility immediately. Fixes jquerygh-1738 Closes jquerygh-5776 (cherry picked from commit ac83749)
Summary
Adds unit tests for the callback-only signatures of animation methods:
show(callback),hide(callback),toggle(callback), and theirslide*andfade*counterparts.Problem
Passing only a callback function (without a duration) to
show(),hide(),toggle(),slideDown(),slideUp(),slideToggle(),fadeIn(),fadeOut(), andfadeToggle()should trigger an animated transition with the default duration (jQuery.fx.speeds._default, 400ms) and invoke the callback on completion.This behavior has been supported historically but was never explicitly tested.
Ref trac-12821
Changes
Added 3 new test cases to
test/unit/effects.jswith 12 total assertions:show/hide/toggle(callback)— verifies callback invocation and correct visibility state after animation completesslideDown/slideUp/slideToggle(callback)— verifies callback invocation for slide animationsfadeIn/fadeOut/fadeToggle(callback)— verifies callback invocation for fade animationsAll tests use the existing
sinon.useFakeTimerspattern and clean up DOM elements after completion.Closes gh-1738
Ref trac-12821