test(04-01): add failing tests for locale-aware formatCurrency

- Test English default locale uses comma grouping (1,234.56)
- Test explicit 'en' locale formatting
- Test 'de' locale uses period grouping and comma decimal (1.234,56)
- Test USD with dollar sign
- Test zero and negative amounts
- Test empty string locale fallback (no RangeError)
- Test default arg does NOT produce German formatting
This commit is contained in:
2026-03-12 09:23:33 +01:00
parent 444baa5187
commit 6ffce76de8

View File

@@ -0,0 +1,46 @@
import { describe, it, expect } from 'vitest'
import { formatCurrency } from './format'
describe('formatCurrency', () => {
it('formats with English locale by default', () => {
const result = formatCurrency(1234.56, 'EUR')
expect(result).toContain('1,234.56')
})
it('formats with explicit English locale using comma grouping and period decimal', () => {
const result = formatCurrency(1234.56, 'EUR', 'en')
expect(result).toContain('1,234.56')
})
it('formats with German locale using period grouping and comma decimal', () => {
const result = formatCurrency(1234.56, 'EUR', 'de')
expect(result).toContain('1.234,56')
})
it('formats USD with English locale including dollar sign', () => {
const result = formatCurrency(1234.56, 'USD', 'en')
expect(result).toContain('$')
expect(result).toContain('1,234.56')
})
it('formats zero correctly', () => {
const result = formatCurrency(0, 'EUR', 'en')
expect(result).toContain('0.00')
})
it('formats negative amounts correctly', () => {
const result = formatCurrency(-500, 'EUR', 'en')
expect(result).toContain('-')
expect(result).toContain('500.00')
})
it('falls back gracefully when locale is empty string (does not throw)', () => {
expect(() => formatCurrency(1234.56, 'EUR', '')).not.toThrow()
})
it('does NOT produce German formatting when called without locale arg', () => {
const result = formatCurrency(1234.56, 'EUR')
// English default should have comma grouping, not period grouping
expect(result).not.toContain('1.234,56')
})
})