-
Notifications
You must be signed in to change notification settings - Fork 617
Update tests from Jest to Vitest #6112
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
03c713c
refactor(test): update Textarea tests from Jest to Vitest
joshblack 4b7d768
refactor(test): update ScrollableRegion tests from Jest to Vitest
joshblack 63f9d68
refactor(test): update RelativeTime test files from Jest to Vitest
joshblack c4bc8f4
refactor(test): update RadioGroup tests from Jest to Vitest
joshblack 4d98135
refactor(test): update Radio tests from Jest to Vitest
joshblack 9a4fc31
chore: update test setup for React act()
joshblack f621f48
refactor(test): update ProgressBar tests from Jest to Vitest
joshblack 86badc1
chore: update textarea tests
joshblack 3b68619
Merge branch 'main' into refactor/update-tests-to-vitest-may-22-2025
joshblack 8c3f9d2
chore: fix eslint error
joshblack bdf4e72
Update packages/react/src/Textarea/Textarea.test.tsx
joshblack bf3b9cd
refactor: update name of module.css
joshblack d349619
chore: update casing for textarea.module.css
joshblack 6f99c60
Merge branch 'main' into refactor/update-tests-to-vitest-may-22-2025
joshblack d13e9e8
Revert " chore: update casing for textarea.module.css"
joshblack 91d4920
Revert "refactor: update name of module.css"
joshblack 89c0ae5
Revert "Update packages/react/src/Textarea/Textarea.test.tsx"
joshblack a0cc40e
Merge branch 'main' into refactor/update-tests-to-vitest-may-22-2025
primer[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 95 additions & 25 deletions
120
packages/react/src/ProgressBar/__snapshots__/ProgressBar.test.tsx.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,98 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`ProgressBar > respects the "progress" prop 1`] = ` | ||
{ | ||
"asFragment": [Function], | ||
"baseElement": <body> | ||
|
||
|
||
|
||
exports[`ProgressBar respects the "progress" prop 1`] = ` | ||
.c0 { | ||
background-color: var(--bgColor-success-emphasis,var(--color-success-emphasis,#1f883d)); | ||
} | ||
|
||
<span | ||
className="ProgressBarContainer" | ||
data-progress-bar-size="default" | ||
data-progress-display="block" | ||
> | ||
<span | ||
aria-label="Upload test.png" | ||
aria-valuemax={100} | ||
aria-valuemin={0} | ||
aria-valuenow={80} | ||
className="c0 ProgressBarItem" | ||
role="progressbar" | ||
style={ | ||
{ | ||
"--progress-bg": "var(--bgColor-success-emphasis)", | ||
"--progress-width": "80%", | ||
} | ||
} | ||
/> | ||
</span> | ||
<div> | ||
<span | ||
class="_ProgressBarContainer_1bos7_27" | ||
data-progress-bar-size="default" | ||
data-progress-display="block" | ||
> | ||
<span | ||
aria-label="Upload test.png" | ||
aria-valuemax="100" | ||
aria-valuemin="0" | ||
aria-valuenow="80" | ||
class="sc-aXZVg lfjCwU _ProgressBarItem_1bos7_11" | ||
role="progressbar" | ||
style="--progress-width: 80%; --progress-bg: var(--bgColor-success-emphasis);" | ||
/> | ||
</span> | ||
</div> | ||
</body>, | ||
"container": <div> | ||
<span | ||
class="_ProgressBarContainer_1bos7_27" | ||
data-progress-bar-size="default" | ||
data-progress-display="block" | ||
> | ||
<span | ||
aria-label="Upload test.png" | ||
aria-valuemax="100" | ||
aria-valuemin="0" | ||
aria-valuenow="80" | ||
class="sc-aXZVg lfjCwU _ProgressBarItem_1bos7_11" | ||
role="progressbar" | ||
style="--progress-width: 80%; --progress-bg: var(--bgColor-success-emphasis);" | ||
/> | ||
</span> | ||
</div>, | ||
"debug": [Function], | ||
"findAllByAltText": [Function], | ||
"findAllByDisplayValue": [Function], | ||
"findAllByLabelText": [Function], | ||
"findAllByPlaceholderText": [Function], | ||
"findAllByRole": [Function], | ||
"findAllByTestId": [Function], | ||
"findAllByText": [Function], | ||
"findAllByTitle": [Function], | ||
"findByAltText": [Function], | ||
"findByDisplayValue": [Function], | ||
"findByLabelText": [Function], | ||
"findByPlaceholderText": [Function], | ||
"findByRole": [Function], | ||
"findByTestId": [Function], | ||
"findByText": [Function], | ||
"findByTitle": [Function], | ||
"getAllByAltText": [Function], | ||
"getAllByDisplayValue": [Function], | ||
"getAllByLabelText": [Function], | ||
"getAllByPlaceholderText": [Function], | ||
"getAllByRole": [Function], | ||
"getAllByTestId": [Function], | ||
"getAllByText": [Function], | ||
"getAllByTitle": [Function], | ||
"getByAltText": [Function], | ||
"getByDisplayValue": [Function], | ||
"getByLabelText": [Function], | ||
"getByPlaceholderText": [Function], | ||
"getByRole": [Function], | ||
"getByTestId": [Function], | ||
"getByText": [Function], | ||
"getByTitle": [Function], | ||
"queryAllByAltText": [Function], | ||
"queryAllByDisplayValue": [Function], | ||
"queryAllByLabelText": [Function], | ||
"queryAllByPlaceholderText": [Function], | ||
"queryAllByRole": [Function], | ||
"queryAllByTestId": [Function], | ||
"queryAllByText": [Function], | ||
"queryAllByTitle": [Function], | ||
"queryByAltText": [Function], | ||
"queryByDisplayValue": [Function], | ||
"queryByLabelText": [Function], | ||
"queryByPlaceholderText": [Function], | ||
"queryByRole": [Function], | ||
"queryByTestId": [Function], | ||
"queryByText": [Function], | ||
"queryByTitle": [Function], | ||
"rerender": [Function], | ||
"unmount": [Function], | ||
} | ||
`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,45 +1,17 @@ | ||||||
import {describe, it, expect, beforeAll, afterAll, vi} from 'vitest' | ||||||
import {render} from '@testing-library/react' | ||||||
import {RadioGroup, FormControl, Radio} from '..' | ||||||
import {behavesAsComponent, checkExports} from '../utils/testing' | ||||||
import userEvent from '@testing-library/user-event' | ||||||
import {RadioGroupContext} from '../RadioGroup' | ||||||
|
||||||
describe('RadioGroup', () => { | ||||||
const mockWarningFn = jest.fn() | ||||||
const mockWarningFn = vi.fn() | ||||||
|
||||||
beforeAll(() => { | ||||||
jest.spyOn(global.console, 'warn').mockImplementation(mockWarningFn) | ||||||
vi.spyOn(console, 'warn').mockImplementation(mockWarningFn) | ||||||
}) | ||||||
|
||||||
afterAll(() => { | ||||||
jest.clearAllMocks() | ||||||
}) | ||||||
|
||||||
behavesAsComponent({ | ||||||
Component: RadioGroup, | ||||||
options: {skipAs: true, skipSx: true}, | ||||||
toRender: () => ( | ||||||
<RadioGroup name="choices"> | ||||||
<RadioGroup.Label>Choices</RadioGroup.Label> | ||||||
<FormControl> | ||||||
<Radio value="one" /> | ||||||
<FormControl.Label>Choice one</FormControl.Label> | ||||||
</FormControl> | ||||||
<FormControl> | ||||||
<Radio value="two" /> | ||||||
<FormControl.Label>Choice two</FormControl.Label> | ||||||
</FormControl> | ||||||
<FormControl> | ||||||
<Radio value="three" /> | ||||||
<FormControl.Label>Choice three</FormControl.Label> | ||||||
</FormControl> | ||||||
</RadioGroup> | ||||||
), | ||||||
}) | ||||||
|
||||||
checkExports('RadioGroup', { | ||||||
default: RadioGroup, | ||||||
RadioGroupContext, | ||||||
vi.clearAllMocks() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The afterAll block clears mock calls but does not restore the original console.warn implementation. Consider using
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
}) | ||||||
|
||||||
it('renders a disabled group of inputs', () => { | ||||||
|
@@ -95,8 +67,8 @@ describe('RadioGroup', () => { | |||||
|
||||||
it('calls onChange handlers passed to RadioGroup and Radio', async () => { | ||||||
const user = userEvent.setup() | ||||||
const handleParentChange = jest.fn() | ||||||
const handleRadioChange = jest.fn() | ||||||
const handleParentChange = vi.fn() | ||||||
const handleRadioChange = vi.fn() | ||||||
const {getByLabelText} = render( | ||||||
<RadioGroup name="choices" onChange={handleParentChange}> | ||||||
<RadioGroup.Label>Choices</RadioGroup.Label> | ||||||
|
@@ -125,7 +97,7 @@ describe('RadioGroup', () => { | |||||
|
||||||
it('calls onChange handler on RadioGroup with selected value', async () => { | ||||||
const user = userEvent.setup() | ||||||
const handleParentChange = jest.fn() | ||||||
const handleParentChange = vi.fn() | ||||||
const {getByLabelText} = render( | ||||||
<RadioGroup name="choices" onChange={handleParentChange}> | ||||||
<RadioGroup.Label>Choices</RadioGroup.Label> | ||||||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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] The snapshot includes the full Testing Library API, making it very verbose. Consider switching to a DOM-only snapshot (e.g. via
asFragment()
ortoJSON()
) to keep snapshots concise and easier to review.Copilot uses AI. Check for mistakes.