You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
angular-mock 1.5.1 TypeError: undefined is not a constructor (evaluating 'angular.element.cleanData(cleanUpNodes)') #14251
My Tests working fine with angular-mock 1.5.0 but with 1.5.1 all Tests fail with: TypeError: undefined is not a constructor (evaluating 'angular.element.cleanData(cleanUpNodes)') in ../node_modules/angular-mocks/angular-mocks.js (line 2776) $$cleanup@../node_modules/angular-mocks/angular-mocks.js:2776:32 $$afterEach@../node_modules/angular-mocks/angular-mocks.js:2746:23
Reacted by Scott MacDowell, Sasha, Arseni Prokharchyk, Bartosz Gerono, mohsenjavidpanah and Hugo Torzuoli
That is strange, since no constructor is being called in that bit of code. Perhaps you can provide some more information? A copy of a failing test, preferably one that we can run.
As a suggestion, you should also try to remove dependencies from your test, and see what exactly triggers the error (you have a lot of dependencies in the application module)
+1, I am receiving a very similar error trying to test a provider.
TypeError: 'undefined' is not a function (evaluating 'angular.element.cleanData(cleanUpNodes)')
at ../node_modules/angular-mocks/angular-mocks.js:2776
at ../node_modules/angular-mocks/angular-mocks.js:2746
Edit: This error occurs with ver 1.5.1, I switched back to 1.5.0 and everything works again.
Reacted by Max Paymar, vinnakota priyatam and Arseni Prokharchyk
@petebacondarwinundefined is not a constructor is the cryptic error PhantomJS gives when you try to call a function that is not defined. It's equivalent to Chrome's a.something is not a function error.
We're getting a similar error on Angular/Mock 1.5.1, which is not an issue on 1.5.0:
# PhantomJS
TypeError: undefined is not a constructor (evaluating 'angular.element('<div ng-app></div>').data('$injector', $injector)')
in /bower_components/angular-mocks/angular-mocks.js (line 2102)
/bower_components/angular-mocks/angular-mocks.js:2102:69
invoke@/bower_components/angular/angular.js:4443:22
/bower_components/angular/angular.js:4261:43
getService@/bower_components/angular/angular.js:4402:46
invoke@/bower_components/angular/angular.js:4434:23
/bower_components/angular/angular.js:4261:43
getService@/bower_components/angular/angular.js:4402:46
invoke@/bower_components/angular/angular.js:4434:23
/bower_components/angular/angular.js:4261:43
getService@/bower_components/angular/angular.js:4402:46
invoke@/bower_components/angular/angular.js:4434:23
/bower_components/angular/angular.js:4265:85
forEach@/bower_components/angular/angular.js:336:24
createInjector@/bower_components/angular/angular.js:4265:10
workFn@/bower_components/angular-mocks/angular-mocks.js:2922:60
# Chrome
TypeError: angular.element(...).data is not a function
at $get (/bower_components/angular-mocks/angular-mocks.js:2102:65)
at Object.invoke (/bower_components/angular/angular.js:4443:17)
at /bower_components/angular/angular.js:4261:37
at getService (/bower_components/angular/angular.js:4402:39)
at Object.invoke (/bower_components/angular/angular.js:4434:13)
at /bower_components/angular/angular.js:4261:37
at getService (/bower_components/angular/angular.js:4402:39)
at Object.invoke (/bower_components/angular/angular.js:4434:13)
at /bower_components/angular/angular.js:4261:37
at getService (/bower_components/angular/angular.js:4402:39)
Do I understand it right that angular.element(...) (which is aliased to jQuery(...) if you load jQuery before Angular) returns something that doesn't have the data method? That seems weird. Could you enable "break on rejections" in Chrome DevTools and then, when you hit this line, check what exactly return the following expressions:
angular.element
angular.element(...) (substitute the dots with what you really have there)
... (substitute the dots with what you had in angular.element)
@kristoff2016, this doesn't seem like the same problem. Please open a new issue, providing more info, e.g. the relevant code, the exact error message, your environament (browser, OS etc). Live reproductions (using CodePen, Plnkr etc) are highly appreciated as well 😁
In my case, the issue was that I was using an old version of karma-phantomjs-launcher (^0.1.4 instead of ^1.0.0) which relied on an older version of PhantomJS. With [email protected], it is working properly.
It's been months since this was first reported and there is still no actual reproduction (with matching versions) posted here!! We can't fix what we can't see. 😟
I am going to close this, but would be happy to re-open if we get a reproduction.
Hi @gkalpak, thanks for taking the time. I was able to reproduce the problem, but apparently we were doing something really naughty in our code 🙈. I have saved in this plnkr. So the following code may not make much sense for you, but we did that as a work around for a very specific situation:
So this works for version 1.5.0 of angular and angular-mocks when testing, but not for 1.5.1-1.5.7. I don't know if it is this specific case or if other cases using angular.element could also break.
Thx @vitorarins. As mentioned before, it is a very "naughty" thing to overwrite such a certal component as angular.element and not at least preserve it's properties. Using the angular.extend() technique described above, you would be good though.
Hi, I am also facing the same issue. But using angular select. In my controller I am initialising select like this.
angular.element('select').select2();
Added spy on as follows :
var ngElement = angular.element('select');
angular.element = angular.extend(function(id) {
try {
return ngElement.call(angular, id);
} catch(err) {
return $(id);
}
}, ngElement);
Activity
petebacondarwin commentedon Mar 16, 2016
That is strange, since no constructor is being called in that bit of code. Perhaps you can provide some more information? A copy of a failing test, preferably one that we can run.
lazarDevelopment commentedon Mar 16, 2016
Here you can find a test, it does nothing but every test we have fails (only for version 1.5.1, 1.5.0 is fine).
Test Runner Karma, Test Framework Jasmine. Project Setup "Foundation for Apps"
https://github.com/HamburgOOU/hoou-webapp/blob/master/test/controllerTest/AboutControllerTest.js
Narretz commentedon Mar 16, 2016
It looks like you are using ui-router, is that right?
Can you try to create a test that runs here: http://plnkr.co/edit/tpl:vojSWqpk1yBjQbbPeXRH?
As a suggestion, you should also try to remove dependencies from your test, and see what exactly triggers the error (you have a lot of dependencies in the application module)
lazarDevelopment commentedon Mar 16, 2016
Yes, using angular-ui-router(0.2.18).
Trommorow I will try to find the dependency who causes it.
scottmacdowell commentedon Mar 16, 2016
+1, I am receiving a very similar error trying to test a provider.
TypeError: 'undefined' is not a function (evaluating 'angular.element.cleanData(cleanUpNodes)')
at ../node_modules/angular-mocks/angular-mocks.js:2776
at ../node_modules/angular-mocks/angular-mocks.js:2746
Edit: This error occurs with ver 1.5.1, I switched back to 1.5.0 and everything works again.
faceleg commentedon Mar 17, 2016
Seeing this here: https://travis-ci.org/likeastore/ngDialog/builds/116420597
nicole-ashley commentedon Mar 18, 2016
@petebacondarwin
undefined is not a constructoris the cryptic error PhantomJS gives when you try to call a function that is not defined. It's equivalent to Chrome'sa.something is not a functionerror.We're getting a similar error on Angular/Mock 1.5.1, which is not an issue on 1.5.0:
Note that we use jQuery alongside Angular.
Could this be at all related to 75373dd?
mgol commentedon Mar 18, 2016
@nikrolls
Do I understand it right that
angular.element(...)(which is aliased tojQuery(...)if you load jQuery before Angular) returns something that doesn't have thedatamethod? That seems weird. Could you enable "break on rejections" in Chrome DevTools and then, when you hit this line, check what exactly return the following expressions:angular.elementangular.element(...)(substitute the dots with what you really have there)...(substitute the dots with what you had inangular.element)Thanks!
60 remaining items
petebacondarwin commentedon May 16, 2016
We still need an actual running reproduction, where all the versions of angular modules used match.
kristoff2016 commentedon Jun 3, 2016
I got this issue: angular.element.parent is not a function
gkalpak commentedon Jun 3, 2016
@kristoff2016, this doesn't seem like the same problem. Please open a new issue, providing more info, e.g. the relevant code, the exact error message, your environament (browser, OS etc). Live reproductions (using CodePen, Plnkr etc) are highly appreciated as well 😁
oliamb commentedon Jun 6, 2016
In my case, the issue was that I was using an old version of karma-phantomjs-launcher (^0.1.4 instead of ^1.0.0) which relied on an older version of PhantomJS. With [email protected], it is working properly.
mcranston18 commentedon Jun 22, 2016
+1 upgrading karma-phantomjs-launcher and phantomjs to 2+ did the trick
vitorarins commentedon Jul 15, 2016
The only option that worked for me until now was downgrading to angular/angular-mocks 1.5.0
gkalpak commentedon Jul 15, 2016
It's been months since this was first reported and there is still no actual reproduction (with matching versions) posted here!! We can't fix what we can't see. 😟
I am going to close this, but would be happy to re-open if we get a reproduction.
vitorarins commentedon Jul 16, 2016
Hi @gkalpak, thanks for taking the time. I was able to reproduce the problem, but apparently we were doing something really naughty in our code 🙈. I have saved in this plnkr. So the following code may not make much sense for you, but we did that as a work around for a very specific situation:
So this works for version
1.5.0of angular and angular-mocks when testing, but not for1.5.1-1.5.7. I don't know if it is this specific case or if other cases usingangular.elementcould also break.gkalpak commentedon Jul 16, 2016
Thx @vitorarins. As mentioned before, it is a very "naughty" thing to overwrite such a certal component as
angular.elementand not at least preserve it's properties. Using theangular.extend()technique described above, you would be good though.Updated plnkr
vitorarins commentedon Jul 18, 2016
Thank you very much @gkalpak! I hope that at least this serves as reference for other people having this problem. Again Thx a lot!
lathaMaramganti commentedon Jul 19, 2016
Hi, I am also facing the same issue. But using angular select. In my controller I am initialising select like this.
angular.element('select').select2();
Added spy on as follows :
var ngElement = angular.element('select');
angular.element = angular.extend(function(id) {
try {
return ngElement.call(angular, id);
} catch(err) {
return $(id);
}
}, ngElement);
spyOn(ngElement, 'select2').and.callFake(function() {
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
TypeError: Attempted to assign to readonly property.
at /node_modules/angular/angular.min.js:9
I had gone through this post fully and used angular 1.5.7 and jasmine 2.4.1. But still issue is not solved.
mgol commentedon Jul 19, 2016
@lathaMaramganti It's not:
but:
You need to save the original function to extend it, not its invocation.