accessing $scope from unit test file when using the vm “ControllerAs” syntax from AngularJS HotTowel

后端 未结 2 1557
栀梦
栀梦 2020-12-28 13:44

See here for example: http://www.johnpapa.net/angularjss-controller-as-and-the-vm-variable/

As the title suggests, I\'m following along on this tutorial [http://tech

相关标签:
2条回答
  • 2020-12-28 13:52

    Ah, obvious now...I can access the vm variable through making a reference to the controller that's created in the test:

     it("should assign Dashboard as title", function () {
           var vm = controller("dashboard", { $scope: scope });
           expect(vm.title).toBe("Dashboard");
        });
    
    0 讨论(0)
  • 2020-12-28 14:05

    you can also do this:

    it("should assign Dashboard as title", function () {
        var controller = controller("dashboard as vm", { $scope: scope });
    
        expect(scope.vm.title).toBe("Dashboard");
    });
    
    0 讨论(0)
提交回复
热议问题