import fc from 'fast-check'; import { describe, expect, it } from 'vitest'; import { formatPrice } from './formatPrice'; const NBSP = '\u00a0'; describe('formatPrice', () => { it('formats whole euros the Dutch way', () => { expect(formatPrice(175)).toBe(`€${NBSP}175`); expect(formatPrice(1250)).toBe(`€${NBSP}1.250`); }); it('gives back the amount from its digits (round-trip)', () => { fc.assert( fc.property(fc.integer({ min: 1, max: 1_000_000 }), (price) => { expect(Number(formatPrice(price).replace(/\D/g, ''))).toBe( price, ); }), ); }); it('starts with the euro sign and a non-breaking space, and has no breaking space (invariant)', () => { fc.assert( fc.property(fc.integer({ min: 1, max: 1_000_000 }), (price) => { const text = formatPrice(price); expect(text.startsWith(`€${NBSP}`)).toBe(true); expect(/[ \t\n\u202f]/.test(text)).toBe(false); }), ); }); });