mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { formatCurrency, formatNumber, Money } from '.';
|
|
|
|
describe('fin utilities', () => {
|
|
it('formats numbers with formatNumber', () => {
|
|
expect(formatNumber(1234567)).toBe(new Intl.NumberFormat('en-US').format(1234567));
|
|
});
|
|
|
|
it('formats currency with defaults', () => {
|
|
const formatted = formatCurrency(1234);
|
|
expect(formatted).toBe(
|
|
new Intl.NumberFormat('en-US', {
|
|
style: 'currency',
|
|
currency: 'EUR',
|
|
minimumFractionDigits: 0,
|
|
maximumFractionDigits: 0,
|
|
}).format(1234)
|
|
);
|
|
});
|
|
|
|
it('money arithmetic preserves cents', () => {
|
|
const a = new Money(10.25); // 10.25 EUR
|
|
const b = new Money(2.5); // 2.50 EUR
|
|
const sum = a.add(b);
|
|
expect(sum.toNumber()).toBeCloseTo(12.75, 5);
|
|
|
|
const mul = a.mul(3);
|
|
expect(mul.toNumber()).toBeCloseTo(30.75, 5);
|
|
});
|
|
|
|
it('money.format delegates to formatCurrency', () => {
|
|
const a = new Money(123.45);
|
|
const formatted = a.format({ currency: 'EUR', locale: 'en-US' });
|
|
expect(formatted).toBe(
|
|
new Intl.NumberFormat('en-US', {
|
|
style: 'currency',
|
|
currency: 'EUR',
|
|
minimumFractionDigits: 2,
|
|
maximumFractionDigits: 2,
|
|
}).format(123.45)
|
|
);
|
|
});
|
|
});
|