frequi_origin/tests/unit/formatters.spec.ts

29 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2024-07-05 12:27:43 +00:00
import { formatPercent, formatPrice, formatPriceCurrency } from '@/utils/formatters/numberformat';
2023-04-11 04:38:26 +00:00
import { describe, it, expect } from 'vitest';
2021-12-18 10:16:15 +00:00
describe('formatters.ts', () => {
it('Format percent correctly', () => {
expect(formatPercent(0.5)).toEqual('50.000%');
});
2021-12-30 08:38:43 +00:00
it('format price currency as expected', () => {
expect(formatPriceCurrency(5123.551123, 'USDT', 3)).toEqual('5123.551 USDT');
expect(formatPriceCurrency(5123.551123, 'USDT')).toEqual('5123.551 USDT');
expect(formatPriceCurrency(5123.551123, 'USDT', 5)).toEqual('5123.55112 USDT');
2023-04-12 16:26:17 +00:00
expect(formatPriceCurrency(5123.551123000001, 'USDT', 5)).toEqual('5123.55112 USDT');
expect(formatPriceCurrency(0.00001, 'BTC', 5)).toEqual('0.00001 BTC');
});
it('Format price correctly', () => {
expect(formatPrice(5123.5123512)).toEqual('5123.5123512');
expect(formatPrice(5123.5123512, 8)).toEqual('5123.5123512');
expect(formatPrice(5123.5123512, 3)).toEqual('5123.512');
2023-04-12 16:26:17 +00:00
expect(formatPrice(5123.512000000001, 8)).toEqual('5123.512');
expect(formatPrice(0.001, 3)).toEqual('0.001');
expect(formatPrice(0.0019, 3)).toEqual('0.002');
expect(formatPrice(2.701e-9, 3)).toEqual('0');
expect(formatPrice(2.701e-9, 8)).toEqual('0');
expect(formatPrice(2.701e-9, 11)).toEqual('0.0000000027');
2021-12-30 08:38:43 +00:00
});
2021-12-18 10:16:15 +00:00
});