【发布时间】:2017-06-24 10:32:00
【问题描述】:
我正在工作的一个项目正在使用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-test-stub 库,并添加了它。这修复了我以前的所有错误,但给我留下了这个:
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 和不使用),更改这些值都不会改变失败的单元测试错误消息。
【问题讨论】:
标签: javascript angularjs unit-testing phantomjs pusher