使用 Jasmine 和 Chutzpah 在 Visual Studio 中测试 TypeScript 和 AngularJS - 找不到变量:angular
Testing TypeScript and AngularJS in Visual Studio with Jasmine and Chutzpah - can't find variable: angular
我正在 Visual Studio Chutzpah 中尝试使用 Jasmine 测试我的 TypeScript 和 AngularJS 代码。在 karma 中测试 运行 正确,但我真的很喜欢 Chutzpah 的 UI。
我的controllerSpecs.ts
:
/// <chutzpah_reference path="../Scripts/angular.js" />
/// <chutzpah_reference path="../Scripts/angular-mocks.js" />
/// <chutzpah_reference path="../Scripts/angular-route.js" />
/// <chutzpah_reference path="../Scripts/angular-resource.js" />
/// <chutzpah_reference path="../Scripts/angular-local-storage.js" />
/// <chutzpah_reference path="../Controllers/MenuController.js" />
/// <chutzpah_reference path="../App/app.js" />
/// <chutzpah_reference path="../references.js" />
/// <reference path="../references.ts" />
describe('Controller Specs', () => {
describe('Menu Controller Specs', () => {
var menuCtrl, scope;
beforeEach(angular.mock.module('typewritingApp'));
beforeEach(() => inject(($rootScope) => {
scope = $rootScope.$new();
menuCtrl = new App.MenuCtrl(scope);
}));
it('should be true', () => {
expect(true).toBe(true);
});
});
});
我的app.ts
:
module App {
var typewritingapp: ng.IModule = angular.module("typewritingApp", [])
.controller("MenuCtrl", ["$scope", MenuCtrl])
}
我的MenuController.ts
:
module App {
export class MenuCtrl {
constructor($scope: any) {
$scope.pageTitle = "Menu";
}
}
}
如果我在测试中将 angular.mock.module
部分更改为 module
(并且我还需要修改 angular-mocks.d.ts 以声明模块),我会收到同样的错误,但它没有找到变量:module.
我有一个错误的 karma 配置文件,在它开始工作后我忘记更新 chutzpah.json 所以这是我的错。感谢@MatthewManela 的帮助
我正在 Visual Studio Chutzpah 中尝试使用 Jasmine 测试我的 TypeScript 和 AngularJS 代码。在 karma 中测试 运行 正确,但我真的很喜欢 Chutzpah 的 UI。
我的controllerSpecs.ts
:
/// <chutzpah_reference path="../Scripts/angular.js" />
/// <chutzpah_reference path="../Scripts/angular-mocks.js" />
/// <chutzpah_reference path="../Scripts/angular-route.js" />
/// <chutzpah_reference path="../Scripts/angular-resource.js" />
/// <chutzpah_reference path="../Scripts/angular-local-storage.js" />
/// <chutzpah_reference path="../Controllers/MenuController.js" />
/// <chutzpah_reference path="../App/app.js" />
/// <chutzpah_reference path="../references.js" />
/// <reference path="../references.ts" />
describe('Controller Specs', () => {
describe('Menu Controller Specs', () => {
var menuCtrl, scope;
beforeEach(angular.mock.module('typewritingApp'));
beforeEach(() => inject(($rootScope) => {
scope = $rootScope.$new();
menuCtrl = new App.MenuCtrl(scope);
}));
it('should be true', () => {
expect(true).toBe(true);
});
});
});
我的app.ts
:
module App {
var typewritingapp: ng.IModule = angular.module("typewritingApp", [])
.controller("MenuCtrl", ["$scope", MenuCtrl])
}
我的MenuController.ts
:
module App {
export class MenuCtrl {
constructor($scope: any) {
$scope.pageTitle = "Menu";
}
}
}
如果我在测试中将 angular.mock.module
部分更改为 module
(并且我还需要修改 angular-mocks.d.ts 以声明模块),我会收到同样的错误,但它没有找到变量:module.
我有一个错误的 karma 配置文件,在它开始工作后我忘记更新 chutzpah.json 所以这是我的错。感谢@MatthewManela 的帮助