Skip to content

Tests: Add unit tests for callback-only animation signatures#5776

Merged
mgol merged 7 commits into
jquery:mainfrom
tommyhgunz14:test/callback-only-animation
Apr 15, 2026
Merged

Tests: Add unit tests for callback-only animation signatures#5776
mgol merged 7 commits into
jquery:mainfrom
tommyhgunz14:test/callback-only-animation

Conversation

@tommyhgunz14
Copy link
Copy Markdown
Contributor

Summary

Adds unit tests for the callback-only signatures of animation methods: show(callback), hide(callback), toggle(callback), and their slide* and fade* counterparts.

Problem

Passing only a callback function (without a duration) to show(), hide(), toggle(), slideDown(), slideUp(), slideToggle(), fadeIn(), fadeOut(), and fadeToggle() 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.js with 12 total assertions:

  1. show/hide/toggle(callback) — verifies callback invocation and correct visibility state after animation completes
  2. slideDown/slideUp/slideToggle(callback) — verifies callback invocation for slide animations
  3. fadeIn/fadeOut/fadeToggle(callback) — verifies callback invocation for fade animations

All tests use the existing sinon.useFakeTimers pattern and clean up DOM elements after completion.

Closes gh-1738
Ref trac-12821

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Feb 18, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@mgol
Copy link
Copy Markdown
Member

mgol commented Feb 18, 2026

Thanks for the PR. Before we review it, please sign our CLA.

Copy link
Copy Markdown
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Please read my comments.

Comment thread test/unit/effects.js Outdated
Comment thread test/unit/effects.js Outdated
@mgol
Copy link
Copy Markdown
Member

mgol commented Feb 23, 2026

Oh, and in the commit message & PR description reference gh-1738 instead of trac-12821. We should use the migrated issues whenever available.

@tommyhgunz14 tommyhgunz14 force-pushed the test/callback-only-animation branch from 35b0cad to b0e9578 Compare February 23, 2026 23:09
Comment thread test/unit/effects.js
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
@tommyhgunz14 tommyhgunz14 force-pushed the test/callback-only-animation branch from b0e9578 to a29f145 Compare February 23, 2026 23:15
Copy link
Copy Markdown
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mgol added Tests Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labels Mar 4, 2026
Copy link
Copy Markdown
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, actually, the tests are failing. Please run them locally and request re-review when they pass.

@mgol mgol removed the Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. label Mar 4, 2026
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
@tommyhgunz14
Copy link
Copy Markdown
Contributor Author

Hi - this has been outstanding for a while now, should still be good.

Copy link
Copy Markdown
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a closer look and I've noticed one other issue, see my comment.

Comment thread test/unit/effects.js
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
@mgol mgol added Needs review Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. and removed Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. Needs review labels Mar 31, 2026
@mgol
Copy link
Copy Markdown
Member

mgol commented Mar 31, 2026

Tests are failing.

@tommyhgunz14
Copy link
Copy Markdown
Contributor Author

Yes - the tests are intentionally demonstrating the bug described in gh-1738. I'll sort out a source fix.

@mgol
Copy link
Copy Markdown
Member

mgol commented Apr 1, 2026

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
@tommyhgunz14
Copy link
Copy Markdown
Contributor Author

Ignore me - mixed up with another PR.
Fixed the timer alignment — the completion tick needs to account for the animation frame interval

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
@tommyhgunz14
Copy link
Copy Markdown
Contributor Author

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.
This should be all green now..

@tommyhgunz14 tommyhgunz14 requested a review from mgol April 1, 2026 21:45
Comment thread test/unit/effects.js Outdated
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
@tommyhgunz14 tommyhgunz14 requested a review from mgol April 2, 2026 08:38
Comment thread test/unit/effects.js Outdated
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
@tommyhgunz14 tommyhgunz14 requested a review from mgol April 2, 2026 14:41
Copy link
Copy Markdown
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mgol mgol added Needs review Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labels Apr 2, 2026
@mgol mgol requested a review from timmywil April 2, 2026 22:15
@timmywil timmywil removed the Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. label Apr 13, 2026
@mgol mgol merged commit ac83749 into jquery:main Apr 15, 2026
16 checks passed
@mgol mgol removed the Needs review label Apr 15, 2026
@mgol mgol added this to the 3.8.0 milestone Apr 15, 2026
mgol pushed a commit that referenced this pull request Apr 15, 2026
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)
mgol pushed a commit to mgol/jquery that referenced this pull request Apr 15, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

Create Unit test for toggle/show/hide( callback )

3 participants