Karma/Jasmine/PhantomJs:未定义不是构造函数 [英] Karma/Jasmine/PhantomJs: undefined is not a constructor
问题描述
我有一个应用程序,在运行测试时会引发一个奇怪的错误.错误如下:
I have an application that raise an odd error when I run tests. The error is the following :
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
这些测试大多数都通过了,但很少有突破.这是一个破坏的测试:
Most of those tests passes, but a very few break. Here is one of the test that breaks:
(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'
});
});
});
});
});
});
})();
我已经坚持了几个小时,似乎找不到解决办法.这是我正在使用的依赖项及其版本:
I've been stuck on that for few hours now and can't seems to find a solution. Here are the dependencies I'm using and their versions:
- 业力:
^1.2.0
- 茉莉花芯:
^2.5.0
- 业力茉莉花:
^1.0.2
- karma-phantomjs-launcher:
^1.0.2
- phantomjs:
^2.1.7
- karma:
^1.2.0
- jasmine-core:
^2.5.0
- karma-jasmine:
^1.0.2
- karma-phantomjs-launcher:
^1.0.2
- phantomjs:
^2.1.7
注意:这是一个使用角度生成器的全新yeoman
应用程序.
NOTE: This is a brand new yeoman
application using the angular generator.
推荐答案
我遇到了同样的问题,但片刻之前就解决了.
I had the same problem, but got it solved moments ago.
要重复我在评论中所说的话:当您有两个等于的数组时,无论发生与否,都会发生该错误.如果它们不相等,则会显示标准差,并显示出差异.
To repeat what I said in the comments: The error happens when you have two arrays that are equal, believe it or not. If they are unequal, you get the standard error with the differences shown.
茉莉核2.5.0.于这一天之前于两天前出版.我降级到2.4.1.,它可以工作.
jasmine-core 2.5.0. was published two days ago, as of this moment. I downgraded to 2.4.1., and it works.
似乎是2.5.0.是罪魁祸首.
It seems that 2.5.0. is the culprit.
降级到2.4.1.,直到发布者解决它.
Downgrade to 2.4.1., until the publisher gets it solved.
我的设置:maven/frontend-maven-plugin/karma(*)/phantomJS
My setup: maven/frontend-maven-plugin/karma(*)/phantomJS
(*)也可能在这里说茉莉花".
(*) could probably have said 'Jasmine' here as well.
这篇关于Karma/Jasmine/PhantomJs:未定义不是构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!