Fact: When angular and angular-mocks do not agree, Jasmine gets angry

Today’s post is more like a “Note to self.” When angular and angular-mocks to not agree, go ahead and make sure they are of the same version*. Otherwise PhantomJS, Firefox, Chrome, etc.. will fail your tests and that’s bad karma** and a bad relationship with Jasmine.

Ok, onto the problem: TypeError angular.element.cleanData is not a function… Did you just see that when trying to run your little nice karma: karma start karma.conf.js (that’s the name we chose for our test configuration file, but your name is most likely different but still a JavaScript file)?

Don’t panic! The guys at Github have something for you. They say it is a known issue (as of when the article was written of course). While some choose to downgrade their angular and angular-mocks to avoid the problem, others just upgrade angular and angular-mocks with the one-liner:

npm update angular angular-mocks -g

Please remember to use sudo if you are on Mac or Linux for this global scope (-g) operation.

With that done, if the tests continue to fail and you have made sure your test scripts are clean, the problem will most likely be resolved with this trick suggested by @KeithPepin in the github solution: go to your angular-mocks.js file (e.g. ~/bower_components/angular-mocks/angular-mocks.js) and replace angular.element.cleanData(cleanUpNodes); with if (angular.element.cleanData) angular.element.cleanData(cleanUpNodes);

And there you go until the people at angular get their act together and fix the issue!

Run your karma file again to see what happens and leave a comment here if you do not get green checks for success!

* You can check versions with npm angular –version and then npm angular-mocks –version

**Don’t get me wrong, this karma here is just for the same of the pun.

Please read more here about unit testing with Angular.

Advertisements

Posted by Rafiki Technology

We learned a ton in school, on the job, but also from great technical insights that others shared on various platforms. We are just giving it back and glorifying Jesus Christ, the Inventor of all human beings. Please note that all information shared on or through our site is of good faith and is not intended to cause any harm individuals, groups, organizations, or devices. Just to be clear: you assume all responsibility for anything you do; we are not liable for anything that should go wrong.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s