fix(rstest): use sync mock factory in mocking example#475
Conversation
rstest no longer supports async mock factories. Load the original module via the `with { rstest: 'importActual' }` import attribute and spread it into a sync factory instead.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe test file 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0a4fbcce9e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| rs.doMock('../src/utils', () => ({ | ||
| formatDate: actualFormatDate, | ||
| generateId: () => 'overridden-id', | ||
| })); |
There was a problem hiding this comment.
Preserve actual exports in the partial mock
In this partial-mock example, the factory now returns only formatDate and the overridden generateId, so the other real exports from ../src/utils (getTimestamp, sleep, log) are no longer available from the mocked module. A user copying this “use the original module implementation alongside mocked parts” pattern and importing one of those original exports will not get the real implementation; import the actual namespace with the rstest: 'importActual' attribute and spread it before overriding generateId.
Useful? React with 👍 / 👎.
Why
The
rstest/mockingexample fails on rstest 0.9.x (eco-ci run):The rstest-side change (rejecting async mock factories) is intentional, so the example needs updating.
What
In
tests/dynamic-mock.test.ts, theshould import actual module inside mockcase used an async factory withawait rs.importActual(...). Switched it to the supported pattern: load the original module via thewith { rstest: 'importActual' }import attribute and use a synchronous factory.Verify
pnpm testinrstest/mocking— all 60 tests pass.