test: cover mini-decimal scientific notation fix#730
Conversation
Summary of ChangesHello, 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 primarily addresses a potential crash in the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
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
|
演练将 Jest 配置从 TypeScript( 变更
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 分钟 诗歌
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #730 +/- ##
=======================================
Coverage 95.31% 95.31%
=======================================
Files 6 6
Lines 299 299
Branches 82 83 +1
=======================================
Hits 285 285
Misses 14 14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request updates @rc-component/mini-decimal to fix a crash with scientific notation and adds a regression test. The Jest configuration is also updated to a simpler JavaScript-based setup to ensure tests run correctly. The changes are logical and directly address the described issue. I have one suggestion to make the new test case more robust.
tests/decimal.test.tsx
Outdated
| }); | ||
|
|
||
| it('should not crash when scientific notation precision exceeds native toFixed limit', () => { | ||
| expect(() => render(<InputNumber defaultValue={1e-307} />)).not.toThrow(); |
There was a problem hiding this comment.
The current test correctly verifies that rendering does not crash. However, it could be strengthened by also asserting that a value is actually rendered in the input. This would prevent future regressions where the component might fail silently (e.g., by rendering an empty string) instead of crashing. The suggested change implicitly keeps the crash check, as render would throw an exception and fail the test if it crashed.
const { container } = render(<InputNumber defaultValue={1e-307} />);
expect(container.querySelector('input').value).not.toBe('');
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/decimal.test.tsx (1)
67-74: 测试用例设计正确,可选的简化建议。回归测试逻辑正确,期望值计算准确。不过 Jest 测试中如果有未捕获的异常会自动失败,因此
expect().not.toThrow()包装器在检测崩溃场景时有些冗余。将其移除可以简化测试结构,并在断言失败时提供更清晰的错误信息。♻️ 可选的简化方案
it('should not crash when scientific notation precision exceeds native toFixed limit', () => { const expectedValue = `0.${'0'.repeat(306)}1`; - expect(() => { - const { container } = render(<InputNumber defaultValue={1e-307} />); - expect(container.querySelector('input').value).toEqual(expectedValue); - }).not.toThrow(); + const { container } = render(<InputNumber defaultValue={1e-307} />); + expect(container.querySelector('input').value).toEqual(expectedValue); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/decimal.test.tsx` around lines 67 - 74, The test wraps the render/assert in expect(...).not.toThrow(), which is redundant because Jest will fail on uncaught exceptions and the wrapper hides clearer failure messages; update the test in tests/decimal.test.tsx by removing the expect(...).not.toThrow() wrapper and directly render the InputNumber (using render(<InputNumber defaultValue={1e-307} />)) then assert that container.querySelector('input').value === expectedValue so failures surface clearly; locate symbols InputNumber, expectedValue, and the container.querySelector('input').value assertion to make the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/decimal.test.tsx`:
- Around line 67-74: The test wraps the render/assert in
expect(...).not.toThrow(), which is redundant because Jest will fail on uncaught
exceptions and the wrapper hides clearer failure messages; update the test in
tests/decimal.test.tsx by removing the expect(...).not.toThrow() wrapper and
directly render the InputNumber (using render(<InputNumber defaultValue={1e-307}
/>)) then assert that container.querySelector('input').value === expectedValue
so failures surface clearly; locate symbols InputNumber, expectedValue, and the
container.querySelector('input').value assertion to make the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 54e3f342-5f1d-4bab-81a0-b6335d28e99f
📒 Files selected for processing (1)
tests/decimal.test.tsx
ref ant-design/ant-design#57152
Summary
Testing
Summary by CodeRabbit
发布说明
测试
Chores