Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a full test suite for the Redux class search slice using MSW for API mocking and Vitest for testing.
- Added
mockSectionsdata and removed the unusedmodelfield in mock messages. - Created
classSearchSlice.test.tsxwith tests for filter/page reducers, successful fetch, and error handling. - Installed MSW in
package.jsonto support request interception in tests.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Client/src/utils/mockData.ts | Defined mockSections: Section[] and updated type imports |
| Client/src/tests/redux/classSearchSlice.test.tsx | Added MSW server handlers and tests for fetchSectionsAsync |
| Client/package.json | Added msw dependency for API mocking in tests |
Comments suppressed due to low confidence (2)
Client/src/tests/redux/classSearchSlice.test.tsx:1
- [nitpick] The test file has no JSX; consider renaming it from
.test.tsxto.test.tsto better reflect its content.
import { describe, it, expect, beforeAll, afterEach, afterAll } from "vitest";
Client/src/tests/redux/classSearchSlice.test.tsx:41
- Add an assertion for the loading state being
trueimmediately after dispatchingfetchSectionsAsync()to cover the pending state behavior.
it("fetches sections and updates state via fetchSectionsAsync", async () => {
| classPair: null, | ||
| isCreditNoCredit: false, | ||
| }, | ||
| ] as Section[]; |
There was a problem hiding this comment.
[nitpick] Remove the redundant as Section[] cast—since you already declared mockSections with type Section[], the explicit cast is unnecessary.
Suggested change
| ] as Section[]; | |
| ]; |
| "eslint-plugin-react-hooks": "^4.6.0", | ||
| "eslint-plugin-react-refresh": "^0.4.6", | ||
| "jsdom": "^26.1.0", | ||
| "msw": "^2.8.5", |
There was a problem hiding this comment.
Move msw into devDependencies instead of dependencies to prevent including test utilities in production bundles.
Suggested change
| "msw": "^2.8.5", |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📌 Summary
Added comprehensive test suite for the class search functionality using MSW (Mock Service Worker) for API mocking and Vitest for testing. This PR introduces unit tests for the Redux class search slice, ensuring proper state management and error handling.
�� Related Issues
Closes #N/A
🛠 Changes Made
classSearchSlice.test.tsxwith comprehensive test coveragemockData.tsmodelfield from mock messages✅ Checklist
📸 Screenshots (if applicable)
N/A - Test implementation only
❓ Additional Notes
The test suite uses MSW to mock the API responses, which allows for testing both successful and error scenarios without making actual network requests. The tests cover the main functionality of the class search feature including:
The implementation follows Redux best practices and ensures proper type safety with TypeScript.