我正在测试服务1取决于另一个服务B.通常这样做的正确方法是$provide在注入A之前使用该对象.但是,我有两个约束:
问题是,到目前为止(我正在测试控制器),我能够从我的测试中访问服务B,我需要注入它.但是要$provide在我的测试中模拟它,我需要在我的测试中访问它,这会产生问题,因为$provide需要在任何之前使用它inject().这是我的测试:
describe('viewsListService', function() {
var viewList,
queryDeferred,
mockViews,
$scope;
beforeEach(module('BoardMocks'));
beforeEach(module('Board'));
beforeEach(inject(function(mockViewsService) {
var query = {};
mockViewsService.init({}, query);
queryDeferred = query.deferred;
mockViews = mockViewsService.mock;
}));
beforeEach(function() {
angular.mock.module('Board', function ($provide) {
$provide.value('Views', mockViews);
});
});
beforeEach(inject(function(viewsListService, $rootScope) {
$scope = $rootScope.$new();
viewList = viewsListService;
// Initialisation of the viewsListService
viewList.init();
queryDeferred.resolve([1]);
$scope.$digest();
}));
describe('getAllViews', function() {
var allViews;
beforeEach(function() {
allViews = viewList.getAllViews();
});
it('should return all the …Run Code Online (Sandbox Code Playgroud)