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:
- karma:
^1.2.0
- jasmine-core:
^2.5.0
- karma-jasmine:
^1.0.2
- karma-phantomjs-launcher:
^1.0.2
- phantomjs:
^2.1.7
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.
jasmine-core 2.5.0. was published two days ago, as of this moment. I downgraded to 2.4.1., and it works.
It seems that 2.5.0. is the culprit.
Downgrade to 2.4.1., until the publisher gets it solved.
My setup: maven/frontend-maven-plugin/karma(*)/phantomJS
(*) could probably have said 'Jasmine' here as well.