大佬教程收集整理的这篇文章主要介绍了angularjs – 如何模拟配置阶段提供程序进行单元测试?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是对正在测试的代码的简化看法:
angular.module('core',['services.configAction']) .config(function(configAction){ configAction.deferIntercept(true); });
上面发生的是我们定义一个具有单一依赖关系的核心模块.
然后,在核心模块的config-block中,我们在configAction对象上调用deferIntercept方法,该方法由services.configAction使用.
这是当前的设置:
describe('core',function() { const configActionProvider={ deferIntercept:jasmine.createSpy('deferIntercept'),$get:function(){ return {/*...*/} } }; beforeEach(function() { module(function($providE) { $provide.provider('configAction',configActionProvider); }); module('core.AppInitializer'); inject(function($injector) { //... }); }); it('should call deferIntercept',function() { expect(configActionProvider.deferIntercept).toHaveBeenCalledWith(true); }); });
问题是它不会覆盖configAction,所以从不调用spy,原始方法是.
如果我将它作为核心模块的依赖项删除它将会这样做,因此angular.module(‘core’,[])而不是angular.module(‘core’,[‘services.configAction’])将起作用,间谍被称为.
以上是大佬教程为你收集整理的angularjs – 如何模拟配置阶段提供程序进行单元测试?全部内容,希望文章能够帮你解决angularjs – 如何模拟配置阶段提供程序进行单元测试?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。