PhantomJS不支持Javascript Internationalization API [英] Javascript Internationalization API is not supported by PhantomJS
问题描述
我对使用ECMAScript Internationalization API的 AngularJs
服务运行了一系列 Jasmine
测试。当我通过Chrome运行它们时,它们都成功运行。但是,当我使用 PhantomJS
通过maven运行它们时,它们都会失败,因为它似乎 PhantomJs
不支持Internationalization API然而。
I have series of Jasmine
tests running against an AngularJs
service that uses ECMAScript Internationalization API. They all run successfully when I run them through Chrome. However, when I use PhantomJS
to run them through maven, they all fail as it seems PhantomJs
does not support Internationalization API yet.
我使用Intl对象获得的测试错误信息是:
The error message I get for the tests using Intl object is :
1:ReferenceError:找不到变量:localService.js中的Intl
1: ReferenceError: Can't find variable: Intl in localizationService.js
其余的测试都失败了。
And the rest of the tests just fail.
测试很简单,看起来像这样:
The tests are simple and look like this:
it('Format date with en-us locale', (function (){
var date= "06/13/2013"
expect(service.date(date,'en-us')).toEqual("6/13/2013");
}))
以及方法service(localizationService.js)是Intl API的简单包装器:
and the methods in service (localizationService.js) are simple wrappers around Intl API:
function getCurrentTimeZone(){
return Intl.DateTimeFormat().resolved.timeZone
}
function date(dateInput,locale,options){
// some other stuff
// ...
if (locale) {
return _date.toLocaleDateString(locale,options);
} else {
return _date.toLocaleDateString();
}
}
我的问题是:
1-我的假设是否正确 PhantomJS v1.9.2
不支持 ECMAScript国际化API
?无论如何要确认吗?
1- Is my assumption correct that PhantomJS v1.9.2
does not support ECMAScript internationalization API
? Is there anyway to confirm that?
2-如何解决此问题?我需要通过maven运行我的测试,我将有更多测试以某种方式触及我的本地化服务API。
谢谢
2- How can I approach resolving this issue? I need to run my tests through maven and I will have more tests hitting my localizationService API one way or the other.
Thanks
推荐答案
不确定您是否使用了Karma,但这是我必须采取的措施来解决同样的问题。
Not sure if you're using Karma or not, but here's what I had to do to fix the same issue.
-
npm install karma-intl-shim --save-dev
这也将安装polyfill库Intl;
This will also install the polyfill library Intl;
将'intl-shim'添加到karma.conf.js中的frameworks集合中:
Add 'intl-shim' to the frameworks collection in karma.conf.js:
...
frameworks: ['intl-shim'],
在karma.conf.js中添加您要测试的语言环境文件,例如'en-US':
Add the locale file you wish to test with in karma.conf.js, for example 'en-US':
...
files: [
'./node_modules/Intl/locale-data/jsonp/en-US.js',
...
这篇关于PhantomJS不支持Javascript Internationalization API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!