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.

我有一系列针对使用ECMAScript国际化API的AngularJs服务运行的茉莉花测试。当我在Chrome上运行时,它们都运行得很成功。然而,当我使用PhantomJS在maven中运行时,它们都失败了,因为PhantomJS似乎还不支持国际化API。

The error message I get for the tests using Intl object is :

我在使用Intl对象进行测试时得到的错误消息是:

1: ReferenceError: Can't find variable: Intl in localizationService.js

1: ReferenceError:在localizationService.js中找不到变量Intl

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");
}))

and the methods in service (localizationService.js) are simple wrappers around Intl API:

服务中的方法(localizationService.js)是围绕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();
        }
}

My questions are:

我的问题是:

1- Is my assumption correct that PhantomJS v1.9.2 does not support ECMAScript internationalization API? Is there anyway to confirm that?

1-我的假设是否正确,PhantomJS v1.9.2不支持ECMAScript国际化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

我如何解决这个问题?我需要通过maven运行我的测试,我将会有更多的测试以一种或另一种方式打击我的localizationService API。谢谢

2 个解决方案

#1


23

Not sure if you're using Karma or not, but here's what I had to do to fix the same issue.

不确定你是否在使用因果报应,但我要做的就是解决同样的问题。

  1. npm install karma-intl-shim --save-dev

    npm安装karma-intl-shim——save-dev

    This will also install the polyfill library Intl;

    这也将安装polyfill库Intl;

  2. Add 'intl-shim' to the frameworks collection in karma.conf.js:

    将“intl-shim”添加到karma.conf.js的框架集合中。

    ...
    frameworks: ['intl-shim'],
    
  3. Add the locale file you wish to test with in karma.conf.js, for example 'en-US':

    添加希望在karma.conf中测试的语言环境文件。js,例如“en - us”:

    ...
    files: [
          './node_modules/Intl/locale-data/jsonp/en-US.js',
    ...
    

更多相关文章

  1. Node.js嬉皮API测试模块安装
  2. 如何测试从实时网站提取数据的AJAX应用程序?
  3. JavaScript中可见性检查的测试条件
  4. 如何测试一个点是否是二次Bézier曲线的一部分?
  5. chai-as-promised:单个测试中的多个期望语句
  6. 如何测试潜在的“浏览器崩溃”JavaScript?
  7. How to learn js properly(week4)使用js建立的动态测试网页
  8. Python PyV8安装测试(Win7)
  9. 如何让django芹菜写入测试数据库进行功能测试?

随机推荐

  1. Android构建时报错: java.io.IOException:
  2. Android开发者的Ane简单入门
  3. android底层开发-android基础架构
  4. android开发中常用的五大布局
  5. Android的UI组件之TextView、EditText
  6. Android_传感器综述
  7. Android(安卓)ListView圆角实现
  8. Android使用FFmpeg(二)--Android Studio
  9. Android五个布局
  10. Android SVG动画PathView源码解析与使用