Angularjs 因果报应错误:未定义myApp
我正在尝试在不同的目录中使用Karma的干净安装来测试Angular seed项目。我还没有修改Angular seed项目。为什么未定义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
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();
});
});