![](/img/trans.png)
[英]AngularJS testing with Jasmine unable to call “angular.mock.module” while using angular-mocks.js
[英]how to mock the dependencies of module in angular js using jasmine
我正在使用茉莉花進行單元測試,在我的情況下,模塊具有一些第三方和一些自定義的依賴關系,我嘗試了一些模擬這些依賴關系的方法,但是它對我不起作用。
下面我的代碼示例
Module.js
var myApp = angular.module('mpapp', ['customservice', "xeditable",'ui.bootstrap', 'ngSanitize']);
testmodule.js
angular.mock.module('customservice', []);
angular.mock.module('xeditable', []);
angular.mock.module('ui.bootstrap', []);
angular.mock.module('ngSanitize', []);
module('myapp');
---這里需要一些測試用例。
這樣,我試圖嘲笑,但它得到錯誤
“ [$ injector:modulerr] http://errors.angularjs.org/1.5.9/ $ injector / modulerr?p0 = eai.pages&p1 = Error%3A%20%5B%24injector%3Amodulerr%5D%20http%3A% 2F%2Ferrors.angularjs.org%2F1.5.9%2F%24injector%2Fmodulerr%3Fp0%3Dui.bootstrap%26p1%3DError%253A%2520%255B%2524injector%253Anomod%255D%2520http%253A%252F%252Ferrors.angularjs。 org%252F1.5.9%252F%2524injector%252Fnomod%253Fp0%253Dui.bootstrap%250A%2520%2520%2520at%2520Anonymous%2520function%2520(file%253A%252F%252F%252Fd%253Ad%25A%252Fvinoth%252Feai%252Fmetlife。 eai-newlayout%252Fmetlife.eai%252Fangular%252Flib%252Fangular.min.js%253A25%253A229)%250A%2520%2520%2520at%2520b%2520(file%253A%252F%252F%252Fd%253A“
因此,請給我任何解決此問題的建議。 謝謝。
我這樣做
beforeEach(
function(){
module('myModule');
inject(function(_$compile_, _$rootScope_,_myService_){
$compile = _$compile_;
$rootScope = _$rootScope_;
myService= _myService_;
//test code here
}
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.