0

好吧,我想为我的控制器做一些单元测试。我已经准备了一些东西,一切正常,除了范围没有正确加载。在我的控制器中,我设置了一个值用户,但在我的测试中,该值没有被设置。

merchantCreateController = ($scope, $location, Users, keyboardManager) ->
    $scope.user= sector: []

现在在我的单元测试中,我想测试用户是否使用该值进行了初始化。

define ["controllers/user", "chai", "angular" ,"angularMocks", "app/services"], (directive, chai, angular, mocks) ->
describe "controllers.user.create", ->
    controller = null
    scope = null
    user= null
    sector = null
    location = null
    beforeEach ->
        mocks.module "app.controllers.user"
    beforeEach ->
        mocks.module "app.services"
    beforeEach ->
        mocks.inject ['$rootScope', '$controller', '$location', 'app.services.user', 'app.services.sector', ($rootScope, $controller, _location, _user, _sector)->
            scope = $rootScope.$new()
            scope.user= sector: []
            user = _user
            location = _location
            sector = _sector
            controller = $controller("app.controllers.merchant.edit",
                $scope: scope,
                $location: location
                "app.services.user": user
                "app.services.sector": sector
                keyboardManager: bind: ->
            )
        ]
    it '$scope.user is initialisized', ->
        console.log scope.user
        chai.expect(scope.user).to.deep.equal sector: []

知道为什么没有定义 scope.user,但其他所有内容都在其中,就像此控制器中的功能一样

4

1 回答 1

0
controller = $controller("app.controllers.merchant.create",
            $scope: scope,
            $location: location
            "app.services.user": user
            "app.services.sector": sector
            keyboardManager: bind: ->
        )

错误是我测试了创建控制器,但我在那里写了编辑:P

于 2013-08-30T09:26:22.477 回答