-
-
Notifications
You must be signed in to change notification settings - Fork 956
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
base: next
Are you sure you want to change the base?
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
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. |
There was a problem hiding this 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 forvi.fn()
/vi.useFakeTimers()
and restored timers withvi.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 unusedsinon
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]) |
There was a problem hiding this comment.
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.
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()); |
There was a problem hiding this comment.
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.
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.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request focuses on replacing the usage of the
sinon
library with thevi
testing utility fromvitest
across multiple test files.