大佬教程收集整理的这篇文章主要介绍了为角度控制器测试注入模拟服务,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我目前的测试:
describe('Player Controllers',function () { beforeEach(function () { this.addMatchers({ toEqualData: function (expected) { return angular.equals(this.actual,expected); } }); }); describe('TestPSPlayerModule',function () { var $httpBACkend,scope,ctrl; beforeEach(module('PSPlayerModule')); beforeEach(inject(function (_$httpBACkend_,$rootScope,$controller) { $httpBACkend = _$httpBACkend_; scope = $rootScope.$new(); ctrl = $controller(PlayerController,{ $scope: scope }); })); it('should request a clip url from the server when clipClicked is called',function () { expect(1).toBe(1); }); }); });
我的控制器如下所示:
w.PlayerController = function ($scope,$http,$window,speedSlider,$LOCATIOn) { ... }
所以这是speedSlider我想嘲笑。
我有一个想法是使用我在测试代码中创建的模块,可以提供速度滑块的假的实现,所以我将以下内容添加到test.js文件的顶部:
@H_949_3@module('TestPSPlayerModule',[]).factory('speedSlider',function () { return = { ... }; });然后在beforeEach()调用中列出该模块,而不是具体的,但是如果我这样做,我会收到以下错误:
Injector already created,can not register a module!
以上是大佬教程为你收集整理的为角度控制器测试注入模拟服务全部内容,希望文章能够帮你解决为角度控制器测试注入模拟服务所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。