Skip to content

test(web): add unit tests for debounce utility - #7359

Open
Goutham-Annem wants to merge 1 commit into
pipe-cd:masterfrom
Goutham-Annem:test/debounce-utility
Open

test(web): add unit tests for debounce utility#7359
Goutham-Annem wants to merge 1 commit into
pipe-cd:masterfrom
Goutham-Annem:test/debounce-utility

Conversation

@Goutham-Annem

Copy link
Copy Markdown

What?

Add web/src/utils/debounce.test.ts — unit tests for the debounce utility.

Why?

debounce.ts had no test coverage. The tests cover all observable behaviours of the function:

  • Does not invoke the wrapped function before the wait period elapses
  • Invokes the wrapped function after the wait period
  • Uses the default 300 ms wait when none is specified
  • Resets the timer on repeated calls and fires only once (debounce semantics)
  • Passes the most recent arguments to the underlying function
  • Can be invoked again after a previous firing
  • clear() cancels a pending invocation
  • clear() is safe to call with no pending invocation

The tests use jest.useFakeTimers() to control setTimeout without real delays, matching the pattern used in other utility test files (e.g. is-stage-running.test.ts, common.test.ts).

Fixes

N/A — self-identified coverage gap.

Does this change affect how the app works for end users?

No — test file only.

Does this change require an update to the documentation?

No.

Covers the core debounce behaviour:
- function is not called before the wait period elapses
- function is called exactly once after the wait period
- default wait of 300 ms is applied when no wait is specified
- repeated calls within the wait window reset the timer and fire only once
- the most recent argument set is forwarded to the underlying function
- the debounced function can be called again after a previous firing
- clear() cancels a pending invocation
- clear() is safe to call with no pending invocation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Goutham Annem <gouthemannem@gmail.com>
@Goutham-Annem
Goutham-Annem requested review from a team as code owners September 9, 2026 19:09
@netlify

netlify Bot commented Sep 9, 2026

Copy link
Copy Markdown

Deploy Preview for pipecd-site canceled.

Name Link
🔨 Latest commit e5c85ff
🔍 Latest deploy log https://app.netlify.com/projects/pipecd-site/deploys/6aa1aedf0a99dc00089f1345

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

👋 Hi @Goutham-Annem, welcome to PipeCD and thanks for opening your first pull request!

We’re really happy to have you here

Before your PR gets merged, please check a few important things below.


Helpful resources


DCO Sign-off

All commits must include a Signed-off-by line to comply with the Developer Certificate of Origin (DCO).

In case you forget to sign-off your commit(s), follow these steps:

For the last commit:

git commit --amend --signoff
git push --force-with-lease

For multiple commits:

git rebase --signoff origin/master
git push --force-with-lease

Run checks locally

Before pushing updates, please run:

make check

This runs the same checks as CI and helps catch issues early.


💬 Need help?

If anything is unclear, feel free to ask in this PR or join us on the CNCF Slack in the #pipecd channel.
You can get your Slack invite from: https://communityinviter.com/apps/cloud-native/cncf

Thanks for contributing to PipeCD! ❤️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new tests include a potential flakiness issue with pending timers and one assertion is too weak to reliably detect incorrect debounce behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds Jest unit tests to improve coverage for the debounce utility in the web frontend, validating key debounce behaviors without introducing runtime application changes.

Changes:

  • Add a new debounce.test.ts suite covering timing, default wait, repeated calls, argument forwarding, re-invocation, and clear() behavior.
File summaries
File Description
web/src/utils/debounce.test.ts Adds unit tests for debounce using Jest fake timers to validate debounce semantics and clear() behavior.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +3 to +9
beforeEach(() => {
jest.useFakeTimers();
});

afterEach(() => {
jest.useRealTimers();
});
Comment on lines +58 to +68
it("passes the most recent arguments to the underlying function", () => {
const fn = jest.fn();
const debounced = debounce(fn, 300);

debounced("first");
jest.advanceTimersByTime(100);
debounced("second");
jest.advanceTimersByTime(300);

expect(fn).toHaveBeenCalledWith("second");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants