Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
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

Closed

Description

@lazarDevelopment

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

Activity

  1. petebacondarwin commented on Mar 16, 2016

    @petebacondarwin
    Contributor

    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.

  2. added this to the 1.5.2 milestone on Mar 16, 2016
  3. lazarDevelopment commented on Mar 16, 2016

    @lazarDevelopment
    Author

    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

  4. Narretz commented on Mar 16, 2016

    @Narretz
    Contributor

    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)

  5. lazarDevelopment commented on Mar 16, 2016

    @lazarDevelopment
    Author

    Yes, using angular-ui-router(0.2.18).
    Trommorow I will try to find the dependency who causes it.

  6. scottmacdowell commented on Mar 16, 2016

    @scottmacdowell

    +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.

  7. nicole-ashley commented on Mar 18, 2016

    @nicole-ashley

    @petebacondarwin undefined 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)
    

    Note that we use jQuery alongside Angular.

    Could this be at all related to 75373dd?

  8. mgol commented on Mar 18, 2016

    @mgol
    Member

    @nikrolls

    angular.element(...).data is not a function

    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:

    1. angular.element
    2. angular.element(...) (substitute the dots with what you really have there)
    3. ... (substitute the dots with what you had in angular.element)

    Thanks!

  9. 60 remaining items

  10. petebacondarwin commented on May 16, 2016

    @petebacondarwin
    Contributor

    We still need an actual running reproduction, where all the versions of angular modules used match.

  11. kristoff2016 commented on Jun 3, 2016

    @kristoff2016

    I got this issue: angular.element.parent is not a function

  12. gkalpak commented on Jun 3, 2016

    @gkalpak
    Member

    @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 😁

  13. reopened this on Jun 3, 2016
  14. oliamb commented on Jun 6, 2016

    @oliamb

    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.

  15. mcranston18 commented on Jun 22, 2016

    @mcranston18

    +1 upgrading karma-phantomjs-launcher and phantomjs to 2+ did the trick

  16. vitorarins commented on Jul 15, 2016

    @vitorarins

    The only option that worked for me until now was downgrading to angular/angular-mocks 1.5.0

  17. gkalpak commented on Jul 15, 2016

    @gkalpak
    Member

    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.

  18. vitorarins commented on Jul 16, 2016

    @vitorarins

    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 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.

  19. gkalpak commented on Jul 16, 2016

    @gkalpak
    Member

    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.

    var ngElement = angular.element;
    angular.element = angular.extend(function(id) {
      try {
        return ngElement.call(angular, id);
      } catch(err) {
        return $(id);
      }
    }, ngElement);

    Updated plnkr

  20. vitorarins commented on Jul 18, 2016

    @vitorarins

    Thank you very much @gkalpak! I hope that at least this serves as reference for other people having this problem. Again Thx a lot!

  21. lathaMaramganti commented on Jul 19, 2016

    @lathaMaramganti

    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.

  22. mgol commented on Jul 19, 2016

    @mgol
    Member

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions