【发布时间】:2014-01-21 13:02:05
【问题描述】:
我目前参与了一个使用 typescript 构建其单页 anuglar 应用程序的项目。不幸的是,他们没有进行单元测试。作为使用打字稿的新手,我在进行任何测试时遇到了问题。下面是一个示例测试。然后是打字稿文件
当我运行测试时,它找不到控制器!
(function() {
'use strict';
describe('CarController', function() {
// Load the controllers module
beforeEach(module('CarDealerApp'));
var scope,
CarController ;
beforeEach(inject(function($controller) {
scope = {};
CarController = $controller('CarController', {
$scope: scope
});
}));
it('should set the car name', function() {
expect(scope.carMake).toEqual('Ford');
});
});
})();
module CarDealerApp.Cars.Controllers {
"use strict";
export interface ICarScope extends angular.Scope {
carName : string;
}
export class CarController {
carName:string = "Ford";
// $inject annotation
public static $inject = [
'$scope'
]
constructor(private $scope: ICarScope){
$scope.vm = this;
}
}
}
【问题讨论】:
-
你不想期待 scope.vm.carMake 还是只做 CarController.carMake?
标签: angularjs typescript karma-runner