【发布时间】:2017-05-14 09:20:32
【问题描述】:
我是单元测试的新手,我正在使用带有 typescript 的 angularjs。对于单元测试,我使用 jasmine 和 chutzpah,但遇到错误“ReferenceError: Can't find variable: angular”
测试文件如
//File:test.ts
///<chutzpah_reference path="../Scripts/angular.js"/>
///<chutzpah_reference path="../Scripts/angular-mocks.js"/>
///<chutzpah_reference path="../Scripts/jasmine/jasmine.js"/>
///<reference path="../scripts/typings/angularjs/angular.d.ts"/>
///<reference path="../scripts/typings/angularjs/angular-mocks.d.ts"/>
///<reference path="../scripts/typings/jasmine/jasmine.d.ts"/>
///<reference path="../controller/testController.ts"/>
module app {
describe("testwithjasmine", () => {
var testController: Testcontroller;
beforeEach(()=> {
testController = new Testcontroller();
})
//This test OK
it("Test controller", () => {
expect(testController.tilte).toBe("title");
})
})
//Error with case below
describe("testInject", () => {
var scope, controller;
beforeEach(angular.mock.module("app"));
beforeEach(() => inject(($controller, $scope) => {
scope = {};
controller = $controller('testController', { $scope: scope });
}));
it("test contrller2", () => {
expect(scope.title).toEqual("title");
})
})
}
chutzpah.json 内容
{
"Compile": {
"Mode": "External",
"Extensions": [".ts"],
"ExtensionsWithNoOutput": [".d.ts"]
},
"References": [
{
"Includes": [
"*/Controller/*.ts"
],
"Excludes": [
"*/Scripts/typings/jasmine/*.d.ts",
"*/scripts/typings/angularjs/*.d.ts"
]
}
],
"Tests": [
{
"Includes": [ "*/Test/*.ts" ],
"Excludes": [
"*/Scripts/Tests/*.d.ts"
]
}
]
}
有什么建议吗? 谢谢!
【问题讨论】:
-
尝试在
"*/Controller/*.ts"之后添加另一行:*/Scripts/angular.js -
感谢@SlavaUtesinov 我添加了“*/Scripts/angular.js”但不起作用。
标签: angularjs unit-testing typescript jasmine chutzpah