相关疑难解决方法(0)

Jasmine angularjs - 监视控制器初始化时调用的方法

我目前正在使用Jasmine与Karma(Testacular)和Web Storm编写单元测试.我在查看控制器初始化时立即调用的方法时遇到问题.是否可以监视控制器初始化时调用的方法?

我的控制器代码,我试图窥探的方法是getServicesNodeList().

myApp.controller('TreeViewController', function ($scope, $rootScope ,$document, DataServices) {
    $scope.treeCollection  =  DataServices.getServicesNodeList();
    $rootScope.viewportHeight = ($document.height() - 100) + 'px';
});
Run Code Online (Sandbox Code Playgroud)

这是测试规范:

describe("DataServices Controllers - ", function () {

beforeEach(angular.mock.module('myApp'));
describe("DataServicesTreeview Controller - ", function () {


    beforeEach(inject(function ($controller, $rootScope, $document, $httpBackend, DataServices) {
        scope = $rootScope.$new(),
        doc = $document,
        rootScope = $rootScope;
        dataServices = DataServices;

        $httpBackend.when('GET', '/scripts/internal/servicedata/services.json').respond(...);

        var controller = $controller('TreeViewController', {$scope: scope, $rootScope: rootScope, $document: doc, DataServices: dataServices });

        $httpBackend.flush();
    }));

    afterEach(inject(function($httpBackend){
        $httpBackend.verifyNoOutstandingExpectation();
        $httpBackend.verifyNoOutstandingRequest();
    }));

    it('should …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing jasmine angularjs

4
推荐指数
1
解决办法
6068
查看次数

标签 统计

angularjs ×1

jasmine ×1

javascript ×1

unit-testing ×1