-
Notifications
You must be signed in to change notification settings - Fork 27.4k
angular-mock 1.5.1 TypeError: undefined is not a constructor (evaluating 'angular.element.cleanData(cleanUpNodes)') #14251
Comments
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. |
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). |
It looks like you are using ui-router, is that right? 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) |
Yes, using angular-ui-router(0.2.18). |
+1, I am receiving a very similar error trying to test a provider. TypeError: 'undefined' is not a function (evaluating 'angular.element.cleanData(cleanUpNodes)') Edit: This error occurs with ver 1.5.1, I switched back to 1.5.0 and everything works again. |
Seeing this here: https://travis-ci.org/likeastore/ngDialog/builds/116420597 |
@petebacondarwin 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? |
Do I understand it right that
Thanks! |
We have a similar problem since angular v1.5.1.
In this case the error is always thrown when the tests includes the
|
@4kochi - you problem is actually that you have spied on a function but not provided an implementation for the spy. In other words, calling You need to provide an implementation for the spy: either a fake or a pass-through:
|
Thanks for the tip @petebacondarwin I had an similar idea. But I wonder then why the exact same test code works with Angular 1.5.0? Did I miss something? |
I have the same issue when I use
|
@dagda1, could you provide the info mentioned in #14251 (comment) (as well as the exact stack trace for the error) ? |
I was seeing this problem as well with our tests after trying to upgrade to v1.5.2. Changing line 2776 of angular-mocks.js from: Fix the issue. In our case, we're trying to spy on angular.element for various reasons. |
That explains the error.
|
BTW, changing the code to |
Thanks @gkalpak - unfortunately any sort of spy (even one that only calls through) seems to cause the same issue. Is there any other work around in the works or other suggestions to try? |
@KeithPepin |
@gkalpak thank you! |
@prestonvanloon : Check the version of angular and angular-mocks you are using. I was facing the same issue. When I was using angular-mocks version 1.5.5 and angular version was 1.4.7, I got the same exception. When I upgraded my angular version to 1.5.5, I did not get any errors and all the tests ran successfully. |
Thanks @varun85jobs and @gkalpak, that was exactly my issue |
Hey guys, I have an Ionic project with angular version 1.5.3 and angular-mocks 1.5.3, but I still get the same error. What could it be? |
Hi, same problem here, I have just tried with 1.5.5 and 1.5.3 and still with problems, as temporal solution we use 1.5.0. |
KeithPepin's answer fixed it for me, but I prefer not to change a library's code |
We still don't have a proper use case for spying on |
There is a question about this issue here as well. I had the same problem and what fixed it to me was to load jquery in my tests:
took the idea from this comment because we also use jQuery alongside Angular. |
We still need an actual running reproduction, where all the versions of angular modules used match. |
I got this issue: angular.element.parent is not a function |
@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. |
+1 upgrading karma-phantomjs-launcher and phantomjs to 2+ did the trick |
The only option that worked for me until now was downgrading to angular/angular-mocks 1.5.0 |
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: var elSelect = angular.element;
angular.element = function(id) {
try {
return elSelect.call(angular, id);
} catch(err) {
return $(id);
}
}; So this works for version |
Thx @vitorarins. As mentioned before, it is a very "naughty" thing to overwrite such a certal component as var ngElement = angular.element;
angular.element = angular.extend(function(id) {
try {
return ngElement.call(angular, id);
} catch(err) {
return $(id);
}
}, ngElement); |
Thank you very much @gkalpak! I hope that at least this serves as reference for other people having this problem. Again Thx a lot! |
Hi, I am also facing the same issue. But using angular select. In my controller I am initialising select like this. Added spy on as follows : spyOn(ngElement, 'select2').and.callFake(function() {
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR I had gone through this post fully and used angular 1.5.7 and jasmine 2.4.1. But still issue is not solved. |
@lathaMaramganti It's not: var ngElement = angular.element('select'); but: var ngElement = angular.element; You need to save the original function to extend it, not its invocation. |
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
The text was updated successfully, but these errors were encountered: