-
-
Notifications
You must be signed in to change notification settings - Fork 802
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
Refactored src/screens/OrganizationEvents.tsx from Jest to Vitest #2559 #3013
Refactored src/screens/OrganizationEvents.tsx from Jest to Vitest #2559 #3013
Conversation
WalkthroughThe pull request focuses on migrating the test file Changes
Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Our Pull Request Approval ProcessThanks for contributing! Testing Your CodeRemember, your PRs won't be reviewed until these criteria are met:
Our policies make our code better. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
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.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/screens/OrganizationEvents/OrganizationEvents.spec.tsx
(5 hunks)
🧰 Additional context used
📓 Learnings (1)
📓 Common learnings
Learnt from: bitbard3
PR: PalisadoesFoundation/talawa-admin#2588
File: src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx:145-155
Timestamp: 2024-12-02T04:20:11.745Z
Learning: In PRs focused solely on refactoring test cases from Jest to Vitest, avoid suggesting optimizations or changes outside the migration scope.
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch
src/screens/OrganizationEvents/OrganizationEvents.spec.tsx
[failure] 76-76:
Property 'DesktopDateTimePicker' does not exist on type 'Promise'.
🔇 Additional comments (5)
src/screens/OrganizationEvents/OrganizationEvents.spec.tsx (5)
25-25
: Nice transition from Jest to Vitest imports.
Looks consistent with the rest of the file.
34-50
: Good approach to mocking window.location
.
This approach provides clear control over location properties in a test environment.
80-84
: Mocking react-toastify
with Vitest looks correct.
Mock definitions are straightforward and aligned with Vitest’s patterns.
99-99
: Swapping global.alert
to vi.fn()
is correct.
This retains the original testing behavior while adhering to Vitest’s mocking.
167-167
: Path-based assertion aligns with the location mock.
Confirming the pathname directly is a reliable approach to ensure correct navigation.
|
Please merge your local branch with the latest upstream, commit and then push to your origin. |
Please fix the failing test |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/screens/OrganizationEvents/OrganizationEvents.spec.tsx (1)
33-49
: Consider using Vitest's built-in window mockThe current window.location mock implementation could be simplified using Vitest's built-in functionality:
-Object.defineProperty(window, 'location', { - value: { - href: 'http://localhost/', - assign: vi.fn((url) => { - const urlObj = new URL(url, 'http://localhost'); - window.location.href = urlObj.href; - window.location.pathname = urlObj.pathname; - window.location.search = urlObj.search; - window.location.hash = urlObj.hash; - }), - reload: vi.fn(), - pathname: '/', - search: '', - hash: '', - origin: 'http://localhost', - }, -}); +vi.stubGlobal('location', { + href: 'http://localhost/', + assign: vi.fn(), + reload: vi.fn(), + pathname: '/', + search: '', + hash: '', + origin: 'http://localhost', +});
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/screens/OrganizationEvents/OrganizationEvents.spec.tsx
(4 hunks)
🧰 Additional context used
📓 Learnings (1)
📓 Common learnings
Learnt from: bitbard3
PR: PalisadoesFoundation/talawa-admin#2588
File: src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx:145-155
Timestamp: 2024-12-02T04:20:11.745Z
Learning: In PRs focused solely on refactoring test cases from Jest to Vitest, avoid suggesting optimizations or changes outside the migration scope.
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch
src/screens/OrganizationEvents/OrganizationEvents.spec.tsx
[failure] 73-73:
Property 'requireActual' does not exist on type 'VitestUtils'.
🔇 Additional comments (3)
src/screens/OrganizationEvents/OrganizationEvents.spec.tsx (3)
79-84
: LGTM: Toast mock implementation
The toast mock is correctly implemented using Vitest's mocking functionality.
98-98
: LGTM: Alert mock and location assertions
The changes correctly implement Vitest's mocking and assertion patterns:
- Global alert mock using
vi.fn()
- Window location assertion using explicit pathname check
Also applies to: 166-166
71-75
:
Fix DateTimePicker mock implementation
The current mock implementation has two issues:
DesktopDateTimePicker
might not exist on the imported module- Type error with
vi.requireActual
Apply this fix:
vi.mock('@mui/x-date-pickers/DateTimePicker', () => {
return {
- DateTimePicker: vi.requireActual(
- '@mui/x-date-pickers/DesktopDateTimePicker',
- ).DesktopDateTimePicker,
+ DateTimePicker: vi.importActual('@mui/x-date-pickers/DateTimePicker')
+ .then((actual) => actual.DateTimePicker),
};
});
Likely invalid or redundant comment.
🧰 Tools
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch
[failure] 73-73:
Property 'requireActual' does not exist on type 'VitestUtils'.
hey @palisadoes could you please help me out a bit how to address this issue, can u refer me some resources for this. |
Please click on the error link. It's explained there |
yeah I finally found a way to do it. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop-postgres #3013 +/- ##
=====================================================
+ Coverage 29.13% 88.94% +59.80%
=====================================================
Files 300 321 +21
Lines 7568 8409 +841
Branches 1652 1836 +184
=====================================================
+ Hits 2205 7479 +5274
+ Misses 5177 688 -4489
- Partials 186 242 +56 ☔ View full report in Codecov by Sentry. |
1bc3c5e
into
PalisadoesFoundation:develop-postgres
…isadoesFoundation#2559 (PalisadoesFoundation#3013) * file name changed * mocking window object * migration success * fixing datetimepicker error * datepicker error fixed * fixed the datepickerError
Refactored src/screens/OrganizationEvents/OrganizationEvents.test.tsx to
src/screens/OrganizationEvents/OrganizationEvents.spec.tsx
Issue: #2559: #2559
Changes Implemented:
Refactored the testing framework from Jest to Vitest in src/screens/OrganizationEvents/OrganizationEvents.test.tsx.
Updated import statements, mocking methods, and assertions to align with Vitest conventions.
Verified compatibility with the existing codebase using Vitest.
OrganizationEvents.test.tsx → OrganizationEvents.spec.tsx to follow the naming convention for Vitest.
Refactor:
src/screens/OrganizationEvents.tsx
from Jest to Vitest #2559Other information
I have read the previous refactor PR and tried to keep things as uniform as possible.
Please suggest any other changes if required.
Summary by CodeRabbit
window.location
and global alert function mocking techniques.