Skip to content

test(react-utils): add initial version of useSticky test suite#682

Open
adamsoderstrom wants to merge 3 commits intofix/use-sticky-viewport-containerfrom
tests/use-sticky
Open

test(react-utils): add initial version of useSticky test suite#682
adamsoderstrom wants to merge 3 commits intofix/use-sticky-viewport-containerfrom
tests/use-sticky

Conversation

@adamsoderstrom
Copy link
Member

@adamsoderstrom adamsoderstrom commented Feb 26, 2026

No description provided.

Copilot AI review requested due to automatic review settings February 26, 2026 16:54
@vercel
Copy link

vercel bot commented Feb 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Mar 2, 2026 7:36am

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 26, 2026

🦋 Changeset detected

Latest commit: 5247d1c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@adamsoderstrom adamsoderstrom changed the base branch from main to fix/use-sticky-viewport-container February 26, 2026 16:54
@adamsoderstrom adamsoderstrom changed the title tests/use sticky test(react-utils): add initial version of useSticky test suite Feb 26, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes useSticky’s fallback stickiness boundary so that when no container is provided it uses viewport dimensions (matching IntersectionObserver’s default root behavior), and introduces an initial test suite for the hook.

Changes:

  • Adjust useSticky boundary-rect logic to fall back to a viewport DOMRect when no container is available.
  • Add a new useSticky test suite covering disabled behavior, observer margin calculation, stickiness transitions, and custom container behavior.
  • Add a changeset describing the behavioral fix.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/react-utils/src/useSticky.ts Aligns fallback stickiness boundary with viewport when container is not provided.
packages/react-utils/src/useSticky.test.ts Adds initial unit tests for useSticky behavior and container handling.
.changeset/rare-dancers-beam.md Documents the behavioral change for a patch release.
.changeset/orange-insects-hide.md Adds an empty changeset file (currently contains no release info).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@                          Coverage Diff                          @@
##           fix/use-sticky-viewport-container     #682      +/-   ##
=====================================================================
+ Coverage                              67.86%   72.48%   +4.62%     
=====================================================================
  Files                                     63       63              
  Lines                                    974      974              
  Branches                                 246      246              
=====================================================================
+ Hits                                     661      706      +45     
+ Misses                                   254      204      -50     
- Partials                                  59       64       +5     

see 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@maeertin maeertin left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@maeertin maeertin left a comment

Choose a reason for hiding this comment

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

thought: Some tests, although valid, perhaps test the actual implementation too much when we might want to keep testing to checking the returned values from the hook. For example in the case of const { result } = renderHook(() => useSticky(ref, [options]) we want to test that result gives back what we want.

On the other hand, we might not get around testing like without simulating actual user scrolling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants