feat:【ActionSheet】测试覆盖提升与组件功能自查 #777
Open
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.
🤔 这个 PR 的性质是?
🔗 相关 Issue
closes #ActionSheet测试覆盖率提升
💡 需求背景和解决方案
背景:
ActionSheet 组件缺乏完善的单元测试覆盖,现有测试覆盖率仅为 50%,无法保证组件功能的稳定性和可靠性。为提升代码质量和组件稳定性,需要对 ActionSheet 组件进行全面的测试覆盖率提升,达到 95%+ 的覆盖率目标。
解决方案:
API 覆盖范围:
ActionSheet 主组件:
visible
,items
,theme
,showCancel
,cancelText
,description
,align
,count
,popupProps
onSelected
,onCancel
,onClose
,onVisibleChange
ActionSheetList 子组件:
items
,align
,onSelected
ActionSheetGrid 子组件:
items
,count
,onSelected
ActionSheetMethod 命令式调用:
show()
,close()
📝 更新日志
测试覆盖率提升:
测试覆盖率成果:
行覆盖率:100% ✅ (目标 95%+)
分支覆盖率:96.55% ✅ (目标 95%+)
函数覆盖率:100% ✅ (目标 95%+)
语句覆盖率:100% ✅ (目标 95%+)
测试用例数:82 个 (全部通过)
本条 PR 不需要纳入 Changelog
☑️ 请求合并前的自查清单
📊 测试覆盖率详情
测试文件结构:
测试场景覆盖:
ActionSheet 主组件测试 (42 个测试用例):
visible
,items
,theme
,showCancel
,cancelText
,description
,align
,count
,popupProps
onSelected
,onCancel
,onClose
,onVisibleChange
回调ActionSheetList 子组件测试 (15 个测试用例):
items
,align
,onSelected
ActionSheetGrid 子组件测试 (14 个测试用例):
items
,count
,onSelected
ActionSheetMethod 命令式调用测试 (7 个测试用例):
show()
,close()
函数可用性模块导出测试 (4 个测试用例):
关键功能验证:
🎯 测试执行结果
🔧 技术改进
解决的技术问题:
beforeEach
中的动态 mocking 替代顶层 vi.mock,避免 "Cannot access before initialization" 错误unmount()
方法和独立渲染避免测试间的 DOM 污染测试质量保证:
📈 覆盖率提升对比
提升前:
提升后: