I am new to unit testing in AngularJS with TypeScript. I have been using jasmine and chutzpah for unit testing, but I encountered an error "ReferenceError: Can't find variable: angular".
My test file looks like this:
//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");
})
})
}
The content of my chutzpah.json file is as follows:
{
"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"
]
}
]
}
Any suggestions on how to resolve this issue would be greatly appreciated. Thank you!