【问题标题】:Checking should have a controller defined检查应该定义一个控制器
【发布时间】:2014-03-14 04:29:58
【问题描述】:

我正在检查我的模块中是否存在PracticeCtrl。我为此编写了以下测试。

给我错误:ReferenceError: myApp is not defined

describe('myApp', function() {
    describe('Controller: PracticeCtrl', function () {            

      // load the controller's module
        beforeEach(function () {
            // Load the controller's module
            module('myApp');    
        });

        it('should have a PracticeCtrl controller', function() {
            expect(myApp.PracticeCtrl).toBeDefined();
        });    

    });
});

如何检查我的模块是否存在控制器?由于我是新手,因此对语法了解较少。

【问题讨论】:

    标签: node.js angularjs unit-testing testing


    【解决方案1】:
    describe("SomeControllerTest", function () {
        var scope, ctrl;
    
        beforeEach(module('myApp'));
    
        beforeEach(inject(function($rootScope, $controller) {
            scope = $rootScope.$new();
            ctrl = $controller('SomeController', {
                $scope: scope
            });
        }));
    
        it("should be defined", function () {
            expect(ctrl).toBeDefined();
        });
    });
    

    【讨论】:

      猜你喜欢
      • 2012-01-06
      • 2014-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-02
      • 1970-01-01
      相关资源
      最近更新 更多