Intl.NumberFormat在Jest单元测试中行为不正确? [英] Intl.NumberFormat behaves incorrectly in Jest unit test?

查看:71
本文介绍了Intl.NumberFormat在Jest单元测试中行为不正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mozilla 网站说:

var number = 123456.789;

console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' })
.format(number));

// expected output: "123.456,79 €"

但是在我的Jest单元测试中,我得到的输出为€123,456.79 ,根据我和Mozilla的示例,这对于 fr-FR 语言环境是不正确的.

But in my Jest unit test, I get as output € 123,456.79 which is not correct for fr-FR locale according to me and Mozilla example.

我尝试加载polyfills和语言环境数据,但似乎无法解决问题

I've tried to load polyfills and locale data, but it does not seem to resolve the issue

import 'intl';
import 'intl/locale-data/complete';
import 'intl/locale-data/jsonp/fr';
import 'intl/locale-data/jsonp/fr-FR';
import 'intl/dist/Intl.complete';

有什么主意吗?

推荐答案

对我有用的解决方案是:

A solution that worked for me is:

  1. npm i full-icu
  2. 使用 NODE_ICU_DATA = node_modules/full-icu jest
  3. 运行测试
  1. npm i full-icu
  2. Run your test with NODE_ICU_DATA=node_modules/full-icu jest

这篇关于Intl.NumberFormat在Jest单元测试中行为不正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆