When testing an IntL money conversion inside Jest, I don't get the correct conversion.
My test:
expect(new Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(50.00)).toBe('R$ 50,00');
// Expected value to be:
// "R$ 50,00"
// Received:
// "R$ 50.00"
When testing an IntL money conversion inside Jest, I don't get the correct conversion.
My test:
expect(new Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(50.00)).toBe('R$ 50,00');
// Expected value to be:
// "R$ 50,00"
// Received:
// "R$ 50.00"
My mand:
jest --config test/unit/jest.conf.js
How can I set the correct locale configuration to Jest?
Share Improve this question edited Nov 5, 2018 at 14:37 skyboyer 23.8k7 gold badges62 silver badges71 bronze badges asked Sep 18, 2018 at 19:19 jotafeldmannjotafeldmann 80211 silver badges18 bronze badges2 Answers
Reset to default 9UPDATE: Full ICU now es with Node.js, since version 13.
Original answer:
The challenge here is to set Node.js i18n, Jest is Node.js based.
Accordingly, with official Node.js documentation, we must set the full-icu parameter.
npm install full-icu
NODE_ICU_DATA=node_modules/full-icu jest --config jest.conf.js
Now the test is correct.
Probably in Brazil use ma sign,
to separate decimal numbers. Instead of dot sign .
.
Here is the link to world map which indicates which country, uses which decimal indicator.
http://www.statisticalconsultants.co.nz/blog/how-the-world-separates-its-decimals.html