Argument 'fn' is not a function, when trying to do unit test with Jasmine and AngularJS

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 03:45:58

I think you may simply have a problem with your configuration for the dependencies for the tests. Without Karma I don't know how you do the tests but I guess you have somewhere a configuration file for Jasmine where you specify the files to be included. You have to include all files and you have to include first all the libraries. Be careful with the order and try to respect the same as you have in your html file that you use to run the application.

If the order is wrong the JS will try to execute before the libraries it needs are included. In your case maybe even the whole angular stack.

Update

Do not forget that Jasmine works using it's own html file and will not include the libraries you usually use if you do not tell it. And also don't forget to include Angular Mock library , essential for your tests

Update 2

Ok I think I found why you have a problem

There is something wrong in this code

beforeEach(module('app', ['ngRoute', 'LocalStorageModule']));

In angular when you call a module using module('smthg',[]) you are creating it, not calling it. You should use this form instead, there is no need to reimport the services that you already included in your main module.

beforeEach(module('app'));

check the Creating versus Retrieval section of the angular documentation https://docs.angularjs.org/guide/module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!