加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Karma / Jasmine / PhantomJs:undefined不是构造

发布时间:2020-12-17 17:17:07 所属栏目:安全 来源:网络整理
导读:我有一个应用程序在运行测试时引发奇怪的错误.错误如下: TypeError: undefined is not a constructor (evaluating 'allKeys[i].match(/^[0-9]+$/)') in node_modules/jasmine-core/lib/jasmine-core/jasmine.js (line 2988)test/spec/core/http/response-sp
我有一个应用程序在运行测试时引发奇怪的错误.错误如下:

TypeError: undefined is not a constructor (evaluating 'allKeys[i].match(/^[0-9]+$/)') in node_modules/jasmine-core/lib/jasmine-core/jasmine.js (line 2988)
test/spec/core/http/response-spec.js:92:63
loaded@http://localhost:8080/context.js:151:17

大多数测试都通过了,但是很少有一些测试.这是打破的测试之一:

(function () {
  'use strict';

  describe('MyAccount.core.http.response',function () {
    var ResponseInterceptor = {},$httpProvider = {},$window = {},env = {},MessageQueue = {};

    beforeEach(module('MyAccount.core.environment'));
    beforeEach(module('MyAccount.core.http',function (_$httpProvider_,$provide) {
      $httpProvider = _$httpProvider_;

      MessageQueue  = {
        dispatch: jasmine.createSpy('dispatch')
      };

      $window = {
        location: {
          href: jasmine.createSpy()
        }
      };

      $provide.value('$window',$window);
      $provide.value('MessageQueue',MessageQueue);
    }));
    beforeEach(inject(function (_$window_,_ResponseInterceptor_,_env_) {
      $window = _$window_;
      ResponseInterceptor = _ResponseInterceptor_;
      env = _env_;
    }));

    describe('response status',function () {
      // Asserting that 404 and 403 errors are intercepted.
      angular.forEach([404,403],function (error) {
        describe('is ' + error,function () {
          beforeEach(function () {
            ResponseInterceptor.responseError({
              status: error,data: {
                message: 'error ' + error
              }
            });
          });

          it('calls MessageQueue.dispatch with the error message',function () {
            expect(MessageQueue.dispatch).toHaveBeenCalledWith('error ' + error,{
              on: 'global.errors'
            });
          });
        });
      });
    });
  });
})();

我已经坚持了几个小时,似乎无法找到解决方案.以下是我正在使用的依赖项及其版本:

>因果报应:^ 1.2.0
> jasmine-core:^ 2.5.0
> karma-jasmine:^ 1.0.2
> karma-phantomjs-launcher:^ 1.0.2
> phantomjs:^ 2.1.7

注意:这是一个使用角度发生器的全新自耕农应用程序.

解决方法

我遇到了同样的问题,但很快就解决了.

重复我在评论中所说的内容:当你有两个相同的数组时,会发生错误,无论信不信由你.如果它们不相等,则会出现标准错误,并显示差异.

茉莉核心2.5.0.两天前发布,截至目前.我降级到2.4.1.它有效.

好像是2.5.0.是罪魁祸首.

降级到2.4.1.,直到出版商得到解决.

我的设置:maven / frontend-maven-plugin / karma(*)/ phantomJS

(*)也可能在这里说“茉莉花”.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读