Javascript 使用AngularJS、Pusher和#x2B进行单元试验;因果报应

Javascript 使用AngularJS、Pusher和#x2B进行单元试验;因果报应,javascript,angularjs,unit-testing,phantomjs,pusher,Javascript,Angularjs,Unit Testing,Phantomjs,Pusher,我正在从事的一个项目是使用Pusher,以及Karma进行单元测试。单元测试当前失败,原因如下: ReferenceError: Can't find variable: Pusher at runBlock (/vagrant/front/src/app/index.run.js:9) at invoke (/vagrant/front/bower_components/angular/angular.js:4771) at /vagrant/front/bower_c

我正在从事的一个项目是使用
Pusher
,以及
Karma
进行单元测试。单元测试当前失败,原因如下:

ReferenceError: Can't find variable: Pusher
    at runBlock (/vagrant/front/src/app/index.run.js:9)
    at invoke (/vagrant/front/bower_components/angular/angular.js:4771)
    at /vagrant/front/bower_components/angular/angular.js:4578
    at forEach (/vagrant/front/bower_components/angular/angular.js:325)
    at createInjector (/vagrant/front/bower_components/angular/angular.js:4578)
    at WorkFn (/vagrant/front/bower_components/angular-mocks/angular-mocks.js:3120)
因此,我查看了
index.run.js
,发现了问题:

    /** @ngInject */
  function runBlock($log,$rootScope) {

    $rootScope.wf = {
      api: '/api/v1',
      dateFormat: 'dd.MM.yyyy',
      dataRefreshListeners:{}
    };


    $rootScope.wf.pusher = new Pusher('3e2d8ab440fad96e67ff', {
       cluster: 'eu',
       encrypted: true
    });

  }
我认为这将是一个定义
Pusher
的简单案例,要么在函数参数中,要么在单元测试中存根它

我找到了
pusher测试存根
库,并添加了它。这修复了我以前的所有错误,但留下了以下错误:

PhantomJS 1.9.8 (Linux 0.0.0) ERROR
  TypeError: 'undefined' is not an object (evaluating 'PusherDefinition.Util')
  at /vagrant/front/bower_components/pusher-test-stub/dist/pusher-test-stub.js:155


[08:51:49] 'test' errored after 3.39 s
[08:51:49] Error: Failed 1 tests.
我确实开始胡乱处理
pusher-test-stub.js
文件,但我认为问题不在于这个库


我还查看了我的
karma.conf.js
文件,记录了目录路径。无论在哪种情况下(使用
pusher-test-stub.js
还是不使用),更改这些值都不会改变失败的单元测试错误消息。

PhantomJS 1.9.8目前非常陈旧(2年以上),在使用现代web应用程序时可能会中断


您应该尝试2.5测试版,它的特点是最近的Webkit引擎:

感谢您的回复,更新了package.json中的phantomjs并运行了npm安装-没有区别。我还想补充一点,单元测试以前是有效的。npm phantomjs包的版本与phantomjs二进制文件本身的版本不同。现在是什么版本<代码>phantomjs--version
可能phantomjs version不对错误负责,但通常情况下,您最好使用此软件的更新版本。该项目运行在一个流浪的盒子中。运行phantomjs——version告诉我程序没有安装。npm文件中指定的版本是“phantomjs”:“~1.9.18”,1.9.18是npm模块“phantomjs”的版本,而不是它驱动的二进制应用程序“phantomjs”。我说的是升级后者。根据能够驱动PhantomJS v2的较新版本判断,+被称为