小编Bla*_*aiz的帖子

尝试在茉莉花单元测试中使用$提供时出错

我正在使用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)

unit-testing coffeescript angularjs

8
推荐指数
1
解决办法
968
查看次数

标签 统计

angularjs ×1

coffeescript ×1

unit-testing ×1