我正在尝试使用Visual Studio在Typescript中实现AngularJS应用程序。示例控制器可以工作,现在我正在尝试编写和运行一些测试。当我创建与Angular不相关的测试时(例如1+1 == 2
),它运行良好。但是,测试控制器功能似乎无效。
这是我的tests.ts
文件:
/// <reference path="../scripts/typings/jasmine/jasmine.d.ts"/>
/// <reference path="../scripts/typings/angularjs/angular.d.ts" />
/// <reference path="../scripts/typings/angularjs/angular-mocks.d.ts" />
/// <reference path="../scripts/typings/angularjs/angular-scenario.d.ts" />
/// <reference path="../app/scripts/controllers.ts"/>
'use strict';
describe("Unit controllers", () => {
beforeEach(() => module("thisApp"));
describe("Sample Controller", () => {
var scope: ISampleScope;
var ctrl;
beforeEach(
function() {
inject(
function($rootScope: ng.IRootScopeService, $controller: ng.IControllerService) {
scope = <ISampleScope> $rootScope.$new();
ctrl = $controller('SampleCtrl', { $scope: scope });
}
);
});
it("should have a message", () => {
expect(element("#msg").text()).toBe("Hello");
});
});
})
运行此示例时,我有3个错误:
ReferenceError: module is not defined
ReferenceError: inject is not defined
ReferenceError: element is not defined
我已经*.d.js
为所有引用的文件添加了文件,以便将它们自动添加到源中,但这无济于事。
我在R#设置中的Jasmine版本是。在所有浏览器和Phantom.JS中都尝试过-结果同样不成功。
有没有人设法使这个工作?
编辑
显然,R#在所有引用之后都附加了Jasmine依赖项,从而引发了该问题。然后,angular-mocks.js
检查window.jasmine
在尝试注册window.module
和window.inject
和失败。
我试图预先包含我自己的Jasmine版本和一个“ bootloader”以使其初始化,这实际上解决了问题module
并且inject
没有进行定义,但是却引发了更深层次的错误。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句