最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I correctly set the local currency when testing with Jest? - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 9

UPDATE: 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

发布评论

评论列表(0)

  1. 暂无评论