fix: 修复类型检查报错并统一有效时间比显示
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { formatRatio } from '@/utils/format'
|
||||
|
||||
describe('formatRatio', () => {
|
||||
it('把 0~1 的比率格式化为一位小数的百分比', () => {
|
||||
expect(formatRatio(0.8)).toBe('80.0%')
|
||||
expect(formatRatio(0.8571)).toBe('85.7%')
|
||||
expect(formatRatio(1)).toBe('100.0%')
|
||||
expect(formatRatio(0)).toBe('0.0%')
|
||||
})
|
||||
|
||||
it('兼容后端返回字符串形式的比率', () => {
|
||||
expect(formatRatio('0.8')).toBe('80.0%')
|
||||
})
|
||||
|
||||
it('空值与非法值统一显示 "-"', () => {
|
||||
expect(formatRatio()).toBe('-')
|
||||
expect(formatRatio(null)).toBe('-')
|
||||
expect(formatRatio('')).toBe('-')
|
||||
expect(formatRatio('abc')).toBe('-')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user