Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 因果报应错误:未定义myApp_Angularjs_Unit Testing_Jasmine_Karma Runner_Karma Jasmine - Fatal编程技术网

Angularjs 因果报应错误:未定义myApp

Angularjs 因果报应错误:未定义myApp,angularjs,unit-testing,jasmine,karma-runner,karma-jasmine,Angularjs,Unit Testing,Jasmine,Karma Runner,Karma Jasmine,我正在尝试在不同的目录中使用Karma的干净安装来测试Angular seed项目。我还没有修改Angular seed项目。为什么未定义myApp和myApp.View1Ctrl 我的测试是: describe("Unit Testing Examples", function () { //beforeEach(angular.mock.module('myApp')); beforeEach(module('myApp')); it('should have

我正在尝试在不同的目录中使用Karma的干净安装来测试Angular seed项目。我还没有修改Angular seed项目。为什么未定义
myApp
myApp.View1Ctrl

我的测试是:

describe("Unit Testing Examples", function () {

    //beforeEach(angular.mock.module('myApp'));

    beforeEach(module('myApp'));

    it('should have a View1Ctrl controller', function () {
        expect(myApp).toBeDefined();
        expect(myApp.View1Ctrl).toBeDefined();
    });
});
输出为:

INFO [watcher]: Changed file "C:/Projects/KarmaJasmine/KarmaJasmine/test/placeho
lder.js".                                                                       
Chrome 37.0.2062 (Windows 8.1) Unit Testing Examples should have a View1Ctrl controller FAILED                                                                  
    ReferenceError: myApp is not defined                                    
        at null.<anonymous> (C:/Projects/KarmaJasmine/KarmaJasmine/test/plac
eholder.js:8:16)                                                                
Chrome 37.0.2062 (Windows 8.1): Executed 6 of 6 (1 FAILED) (0 secs / 0.054 secs)
Chrome 37.0.2062 (Windows 8.1): Executed 6 of 6 (1 FAILED) (0.061 secs / 0.054 s
ecs)                                                      

如果我需要发布更多详细信息,请告诉我。我试图通读所有类似的问题,但没有找到答案。

您有
myApp
变量未在规范中定义。请定义它:

describe("Unit Testing Examples", function () {
    var myApp;

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

    it('should have a View1Ctrl controller', function () {
        expect(myApp).toBeDefined();
        expect(myApp.controller('View1Ctrl')).toBeDefined();
    });
});
还有一个案例演示。

相关。
describe("Unit Testing Examples", function () {
    var myApp;

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

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