Given the code:
import { getLocale } from './locale';
export const euro = (priceData: number): string => {
const priceFormatter = new Intl.NumberFormat(getLocale(), {
style: 'currency',
currency: 'EUR',
});
return priceFormatter.format(priceData);
}
export default null;
and the related test:
import { euro } from './currency';
test('euro', () => {
expect(euro(42)).toBe("42,00 €");
});
Jest says:
Even if I copy-paste the expected result of Jest to my assert, the error is still the same.
So the question is: Why the hell? :-D
You want this test to assert:
"42,00\xa0€"
It's not a space (different ascii code / unicode). According to a jest issue about string comparison being incorrect Intl.NumberFormat
uses a non-breaking space.
And as pointed out in a similar question's answer:
NumberFormat use small non-breaking space (
\u202f
) for thousand separator and normal non-breaking space beforece currency (\xa0
).