Jasmine test to test if the controller is defined

做~自己de王妃 提交于 2019-12-04 16:47:17

You should inject all the dependencies in the controller first before mocking it.

Try this:

// MatchController.spec.js
(function(){
'use strict';
describe('controller: MatchController', function(){

    var module, MatchController, APP_CONFIG, $authUser, $http, $rootScope, $state, $stateParams, SearchService, ConfirmMatchService, MusicOpsService, ContentOpsService, MatchstickService, MatchService, Restangular;

    beforeEach(function() {
        module = angular.module('app.match');
    });

    beforeEach(inject(function ($controller, _APP_CONFIG_, _$authUser_, _$http_, _$rootScope_, _$state_, _$stateParams_, _SearchService_, _ConfirmMatchService_, _MusicOpsService_, _ContentOpsService_, _MatchstickService_, _MatchService_, _Restangular_) {

        APP_CONFIG = _APP_CONFIG_;
        $authUser = _$authUser_;
        $http = _$http_;
        $rootScope = _$rootScope_;
        $state = _$state_;
        $stateParams = _$stateParams_;
        SearchService = _SearchService_;
        ConfirmMatchService = _ConfirmMatchService_;
        MusicOpsService = _MusicOpsService_;
        ContentOpsService = _ContentOpsService_;
        MatchstickService = _MatchstickService_;
        MatchService = _MatchService_;
        Restangular = _Restangular_;

        MatchController = $controller('MatchController', {
            APP_CONFIG: _APP_CONFIG_,
            $authUser: _$authUser_,
            $http: _$http_,
            $rootScope: _$rootScope_,
            $state: _$state_,
            $stateParams: _$stateParams_,
            SearchService: _SearchService_,
            ConfirmMatchService: _ConfirmMatchService_,
            MusicOpsService: _MusicOpsService_,
            ContentOpsService: _ContentOpsService_,
            MatchstickService: _MatchstickService_,
            MatchService: _MatchService_,
            Restangular: _Restangular_
        });


    }));

    describe("Match controller to be defined", function() {

        it("should be created successfully", function () {
            expect(MatchController).toBeDefined();
        });

    });

});

})();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!