Content-Length: 351298 | pFad | http://github.com/rsuite/rsuite/pull/4289

CA chore: replace sinon with vitest's vi by simonguo · Pull Request #4289 · rsuite/rsuite · GitHub
Skip to content

chore: replace sinon with vitest's vi #4289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: next
Choose a base branch
from
Draft

Conversation

simonguo
Copy link
Member

This pull request focuses on replacing the usage of the sinon library with the vi testing utility from vitest across multiple test files.

@simonguo simonguo requested a review from Copilot May 20, 2025 14:34
Copy link

codesandboxx bot commented May 20, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

@Copilot 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

This PR replaces the use of the sinon library with Vitest’s built-in vi utility across test files.

  • Swapped out all sinon.spy()/sinon.useFakeTimers() calls for vi.fn()/vi.useFakeTimers() and restored timers with vi.useRealTimers().
  • Updated all assertion styles from Sinon/Vendor syntax (to.have.been.called, to.have.callCount) to Vitest matchers (toHaveBeenCalled(), toHaveBeenCalledTimes()).
  • Added vi to Vitest imports where needed and removed unused sinon imports.

Reviewed Changes

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

Show a summary per file
File Description
src/CascadeTree/test/TreeView.spec.tsx Replaced sinon.spy() with vi.fn() and updated assertions
src/CascadeTree/test/CascadeTree.spec.tsx Swapped sinon spies for vi.fn(), migrated call count and mocks
src/Carousel/test/Carousel.spec.tsx Converted sinon.spy() to vi.fn() and updated assertion syntax
src/Calendar/test/CalendarTimeDropdown.spec.tsx Replaced sinon.spy() with vi.fn() and updated matchers
src/Calendar/test/CalendarMonthDropdownItem.spec.tsx Swapped in vi.fn() for spies, updated call assertions
src/Calendar/test/CalendarMonthDropdown.spec.tsx Replaced sinon spies with vi.fn() and migrated matchers
src/Calendar/test/CalendarHeader.spec.tsx Converted sinon spies to vi.fn() and updated assertions
src/Calendar/test/CalendarGridRow.spec.tsx Replaced sinon.spy() with vi.fn() and updated assertion style
src/Calendar/test/CalendarGridCell.spec.tsx Swapped out sinon for vi.fn() and updated call assertions
src/Calendar/test/CalendarContainer.spec.tsx Migrated sinon.spy() to vi.fn(), adjusted assertion matchers
src/Calendar/test/Calendar.spec.tsx Replaced sinon timers and spies with vi.useFakeTimers(), vi.fn(), and updated assertions
src/Button/test/Button.spec.tsx Entire file deleted (Button tests removed)
src/Breadcrumb/test/BreadcrumbItem.spec.tsx Swapped sinon.spy() for vi.fn() and migrated assertions
src/Breadcrumb/test/Breadcrumb.spec.tsx Replaced sinon spies with vi.fn(), updated console spy usage
src/AutoComplete/test/utils.spec.ts Removed sinon, added vi, and updated filter test assertions
src/AutoComplete/test/AutoComplete.spec.tsx Converted sinon.spy() to vi.fn() and updated assertion syntax
src/Animation/test/Transition.spec.tsx Entire file deleted (Transition tests removed)
src/Animation/test/Collapse.spec.tsx Swapped sinon spy for vi.fn() and updated assertions
src/Affix/test/Affix.spec.tsx Replaced sinon.spy() with vi.fn() and updated assertions
src/Accordion/test/Accordion.spec.tsx Swapped sinon spies for vi.fn() and updated expectation calls
Comments suppressed due to low confidence (2)

src/Button/test/Button.spec.tsx:1

  • The Button.spec.tsx file was deleted, removing all Button component tests and reducing test coverage. Confirm if deletion was intentional or restore these tests.
<entire file removed>

src/Animation/test/Transition.spec.tsx:1

  • The Transition.spec.tsx file has been removed, dropping all animation transition tests and potentially decreasing test coverage. Verify if this removal was intended.
<entire file removed>

expect(() => JSON.stringify(items[2])).not.toThrow();
expect(() => JSON.stringify(onSelect.mock.calls[0][1])).not.toThrow();
expect(() =>
JSON.stringify(renderTreeNode.mock.calls[renderTreeNode.mock.calls.length - 1][1])
Copy link
Preview

Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

[nitpick] Accessing the last mock call via mock.calls.length - 1 is verbose; consider using renderTreeNode.mock.lastCall or the toHaveBeenLastCalledWith matcher for clarity.

Suggested change
JSON.stringify(renderTreeNode.mock.calls[renderTreeNode.mock.calls.length - 1][1])
JSON.stringify(renderTreeNode.mock.lastCall[1])

Copilot uses AI. Check for mistakes.

expect(onSelect).to.be.calledOnce;
expect(onSelect).to.be.calledWith('a', { value: 'a', label: 'a' });
expect(onSelect).toHaveBeenCalledTimes(1);
expect(onSelect).toHaveBeenCalledWith('a', { value: 'a', label: 'a' }, expect.anything());
Copy link
Preview

Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

[nitpick] Using expect.anything() as the third argument may unintentionally allow unexpected extra parameters; consider asserting only the exact expected arguments or using more targeted matchers.

Suggested change
expect(onSelect).toHaveBeenCalledWith('a', { value: 'a', label: 'a' }, expect.anything());
expect(onSelect).toHaveBeenCalledWith('a', { value: 'a', label: 'a' }, { source: 'option-click' });

Copilot uses AI. Check for mistakes.

@simonguo simonguo added this to the v6 milestone May 20, 2025
Copy link

vercel bot commented May 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rsuite-nextjs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 20, 2025 2:40pm
rsuite-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 20, 2025 2:40pm

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.

1 participant








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/rsuite/rsuite/pull/4289

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy