我正在使用AngularJS并尝试测试一个调用工厂来获取一些数据的控制器.
这是控制器代码:
'use strict'
angular.module('AngularApp')
.controller 'IndexCtrl', ($scope, session, navigation) ->
session.find().then (response) ->
$scope.session = response.data
$scope.someOtherVariable = {}
Run Code Online (Sandbox Code Playgroud)
当然,我想用模拟交换工厂,以防止调用真正的API.我正在尝试使用$ provide.factory来注入模拟副本:
'use strict'
describe 'Controller: IndexCtrl', ->
# load the controller's module
beforeEach module 'mosaicAdminWebClientApp'
beforeEach module ($provide) ->
$provide.factory 'session', ->
true
IndexCtrl = {}
scope = {}
# Initialize the controller and a mock scope
beforeEach inject ($controller, $rootScope) ->
scope = $rootScope.$new()
IndexCtrl = $controller 'IndexCtrl', {
$scope: scope
}
it 'should attach a list of …Run Code Online (Sandbox Code Playgroud)