Jest: test Intl.DateTimeFormat

心不动则不痛 提交于 2019-12-05 07:36:23

The only solution that I managed to find to this problem was to install full-icu which seemed to provide the right locales to node during the testing process.

That package is needed because node by default only ships with a limited set of locales, explained here: https://nodejs.org/docs/latest-v9.x/api/intl.html

With that package installed, the additional step that I had to take was to change my test command to use:

"test": "NODE_ICU_DATA=node_modules/full-icu jest --config jest.config.js"

I ran into this problem in a couple of different environments. When running the tests locally on Mac OS and also when running the tests inside a Docker container during CI.

Interestingly, I don't need to use the export when running the tests via WebStorm's Jest integration. It definitely seems like the behaviour of the Intl library is far from stable in node.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!