gpt4 book ai didi

angularjs - karma 报应/ Jasmine /PhantomJs : undefined is not a constructor

转载 作者:行者123 更新时间:2023-12-03 06:54:45 25 4
gpt4 key购买 nike

我有一个应用程序在运行测试时引发奇怪的错误。错误如下:

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'
});
});
});
});
});
});
})();

我已经被困在这个问题上几个小时了,似乎找不到解决方案。以下是我正在使用的依赖项及其版本:

  • karma :^1.2.0
  • Jasmine 核心:^2.5.0
  • karma Jasmine :^1.0.2
  • karma-phantomjs-启动器:^1.0.2
  • phantomjs:^2.1.7

注意:这是一个使用 Angular 生成器的全新 yeoman 应用程序。

最佳答案

我也遇到了同样的问题,不过很快就解决了。

重复我在评论中所说的话:无论你相信与否,当你有两个相等的数组时,就会发生错误。如果它们不相等,您将得到标准错误并显示差异。

Jasmine 核心2.5.0。两天前发布,截至目前。我降级到 2.4.1.,它可以工作。

好像是2.5.0。是罪魁祸首。

降级到2.4.1.,直到发布者解决问题。

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

(*) 也可能在这里说“ Jasmine ”。

关于angularjs - karma 报应/ Jasmine /PhantomJs : undefined is not a constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39288777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com