Angularjs 嵌套描述块中的Jasmine spy未设置

Angularjs 嵌套描述块中的Jasmine spy未设置,angularjs,coffeescript,jasmine,Angularjs,Coffeescript,Jasmine,我有下面的jasmine测试脚本 'use strict' describe 'module:login:controller', () -> $controller = null $rootScope = null $state = null $scope = null User = null Page = null controller = null beforeEach module 'forge' beforeEach inject((_$

我有下面的jasmine测试脚本

'use strict'

describe 'module:login:controller', () ->
  $controller = null
  $rootScope = null
  $state = null
  $scope = null
  User = null
  Page = null
  controller = null

  beforeEach module 'forge'

  beforeEach inject((_$controller_, _$rootScope_, _$state_, _User_, _Page_) ->
    $controller = _$controller_
    $rootScope = _$rootScope_
    $state = _$state_
    User = _User_
    Page = _Page_

    $state =
      go: () ->
        return

    $scope = {}

    spyOn(User,'isAuthenticated')
    spyOn($state, 'go')
    spyOn(User,'resetData')
    spyOn(Page,'addAlert')
  )

  it 'should check true login status and redirect to home', () ->
    User.isAuthenticated.and.returnValue true
    controller = $controller 'loginController', {$rootScope:$rootScope, $scope: $scope, $state: $state, User: User, Page: Page}
    expect($state.go).toHaveBeenCalledWith 'home'

  it 'should check false login status and setup scope', () ->
    User.isAuthenticated.and.returnValue false

    controller = $controller 'loginController', {$rootScope:$rootScope, $scope: $scope, $state: $state, User: User, Page: Page}
    expect($state.go).not.toHaveBeenCalledWith 'home'
    expect(User.resetData).toHaveBeenCalled

    expectedScope =
      email: 'robot@site.com'
      password: 'password'
      store: null
      stores: []

    expect($scope.email).toEqual expectedScope.email
    expect($scope.password).toEqual expectedScope.password
    expect($scope.store).toEqual expectedScope.store
    expect($scope.stores).toEqual expectedScope.stores

  describe 'method calls', () ->
    beforeEach User.isAuthenticated.and.returnValue false

    it 'should add Alert if email is empty', () ->
      spyOn(Page,'addAlert')

      controller = $controller 'loginController', {$rootScope: $rootScope, $scope: $scope, $state: $state, User: User, Page: Page}

      $scope.email = ''

      $scope.login()

      expect(Page.addAlert).toHaveBeenCalledWith 'danger', 'Missing Email'
我试图在测试中重复使用间谍,并在需要时更新预期

运行测试时,错误输出显示:

Chrome 48.0.2564 (Mac OS X 10.11.3) module:login:controller method calls encountered a declaration exception FAILED
  TypeError: Cannot read property 'isAuthenticated' of null
    at Suite.<anonymous> (/Users/usr/proj/src/module/login/test/unit/controller/login.unit.js:62:20)
    at Suite.<anonymous> (/Users/proj/src/module/login/test/unit/controller/login.unit.js:61:10)
    at /Users/ianwood/Documents/repos/moltin/forge/src/module/login/test/unit/controller/login.unit.js:2:1
Chrome 48.0.2564 (Mac OS X 10.11.3): Executed 65 of 65 (1 FAILED) (1.171 secs / 1.148 secs)
Chrome 48.0.2564(Mac OS X 10.11.3)模块:登录:控制器方法调用遇到声明异常失败 TypeError:无法读取null的属性“isAuthenticated” 在套房。(/Users/usr/proj/src/module/login/test/unit/controller/login.unit.js:62:20) 在套房。(/Users/proj/src/module/login/test/unit/controller/login.unit.js:61:10) at/Users/ianwood/Documents/repos/moltin/forge/src/module/login/test/unit/controller/login.unit.js:2:1 Chrome 48.0.2564(Mac OS X 10.11.3):执行65次(1次失败)(1.171秒/1.148秒) 建议用户为空

我确实注意到子描述是在之前执行的,所以外部描述测试是在最后运行的,但是我想知道如何在子描述块之间共享