Add unit tests for utils and module pure functions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-05 19:14:13 +08:00
parent e596bcd18e
commit 83c2db7582
8 changed files with 563 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import { describe, it, expect } from 'vitest';
import shortScaleNumber from '@/module/shortScaleNumber.js';
describe('shortScaleNumber', () => {
it('returns small numbers without abbreviation', () => {
expect(shortScaleNumber(1).trim()).toBe('1');
expect(shortScaleNumber(999).trim()).toBe('999');
});
it('abbreviates thousands as k', () => {
expect(shortScaleNumber(1000).trim()).toBe('1k');
expect(shortScaleNumber(1500).trim()).toBe('1.5k');
});
it('abbreviates millions as m', () => {
expect(shortScaleNumber(1000000).trim()).toBe('1m');
});
it('abbreviates billions as b', () => {
expect(shortScaleNumber(1000000000).trim()).toBe('1b');
});
it('abbreviates trillions as t', () => {
expect(shortScaleNumber(1000000000000).trim())
.toBe('1t');
});
it('rounds up using Math.ceil', () => {
// 1234 -> 1.234k -> ceil(12.34)/10 = 1.3k
expect(shortScaleNumber(1234).trim()).toBe('1.3k');
});
it('handles zero', () => {
expect(shortScaleNumber(0).trim()).toBe('0');
});
});