大佬教程收集整理的这篇文章主要介绍了单元测试 – AngularJS – 具有值依赖注入的单元测试服务,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
//App declaration angular.module('myApp',['myApp.services']).value('someUrl','http://www.example.com'); //service declaration angular.module('myApp.services',['someUrl']).factory('Myservice',function(someUrl) { var data; "Do stuff" return data; });
现在,我正在尝试对此进行单元测试,但我无法正确设置“someUrl”参数.我尝试过这样的事情,没有成功:
angular.module('myApp','test/test.json'); describe('services',function() { beforeEach(module('myApp.services')); describe('Myservice',function() { it('should return {success: truE}',inject(function() { expect(data).toEqual({success: truE}); })); }); });
无论如何,有一个更好的方法.您可以使用模拟模块注入$provide,以便您可以覆盖任何依赖项.
这是您的规格看起来像:
describe('services',function() { // here we load the module myApp and load an additional one that // allows you to override your dependency beforeEach(module('myApp',function($providE) { $provide.value('someUrl','test/test.json'); })); describe('Myservice',function() { it('should return {success: truE}',inject(function() { expect(data).toEqual({success: truE}); })); }); });
以上是大佬教程为你收集整理的单元测试 – AngularJS – 具有值依赖注入的单元测试服务全部内容,希望文章能够帮你解决单元测试 – AngularJS – 具有值依赖注入的单元测试服务所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。