docs: clarify mock behavior in vitest migration guide#912
Conversation
Clarifies the auto-mocking behavior of Vitest and Rstest in the migration guide.
- Explains that Vitest's vi.mock() without a factory first checks for a __mocks__ directory before falling back to auto-mocking.
- Explains that Rstest's rs.mock() requires the explicit { mock: true } option for auto-mocking and only checks for __mocks__ otherwise.
- Updates both the English and Chinese documentation.
Summary of ChangesHello @9aoy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Vitest migration guide by providing crucial clarifications on how module auto-mocking functions differently between Vitest and Rstest. It aims to prevent confusion for users migrating their testing setups by explicitly outlining the distinct behaviors of Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request clarifies the auto-mocking behavior in the Vitest migration guide by adding a new section that compares Vitest and Rstest. The explanation is clear and the code examples are helpful. I've found a broken link in the Chinese documentation and suggested a minor wording improvement for the English version to enhance clarity. Overall, a great addition to the documentation.
| }); | ||
| ``` | ||
|
|
||
| 这种区别很重要:Vitest 默认提供了隐式的自动模拟回退,而 Rstest 则需要显式配置才能实现相同的行为。更多详细信息,请参阅 [`rs.mock()` 的 `{ mock: true }` 选项](/api/runtime-api/rstest/mock-modules#with-mock-true-option)。 |
There was a problem hiding this comment.
The link to the API documentation appears to be broken. The anchor #with-mock-true-option points to an ID that doesn't exist on the Chinese page. The correct anchor for the header '使用 { mock: true } 选项' is #使用-mock-true-选项. Please update the link to fix it.
这种区别很重要:Vitest 默认提供了隐式的自动模拟回退,而 Rstest 则需要显式配置才能实现相同的行为。更多详细信息,请参阅 [`rs.mock()` 的 `{ mock: true }` 选项](/api/runtime-api/rstest/mock-modules#使用-mock-true-选项)。
| }); | ||
| ``` | ||
|
|
||
| Rstest handles this differently. Calling `rs.mock()` with only the module path will _only_ look for a mock in the `__mocks__` directory and will error if one isn't found. To achieve auto-mocking, you must explicitly pass the `{ mock: true }` option. |
There was a problem hiding this comment.
The phrase 'will error' is a bit informal for documentation. Using 'throws an error' would be more precise and professional.
Rstest handles this differently. Calling `rs.mock()` with only the module path will _only_ look for a mock in the `__mocks__` directory and throws an error if one isn't found. To achieve auto-mocking, you must explicitly pass the `{ mock: true }` option.
Summary
Clarifies the auto-mocking behavior of Vitest and Rstest in the migration guide.
vi.mock()without a factory first checks for a__mocks__directory before falling back to auto-mocking.rs.mock()requires the explicit{ mock: true }option for auto-mocking and only checks for__mocks__otherwise.Related Links
Checklist