【发布时间】:2016-04-11 12:28:24
【问题描述】:
我对使用 Jasmine 进行 AngularJs 单元测试非常陌生。所以你能告诉我如何使用 Jasmine 测试下面提到的控制器和 countyService.getAllCountiesAsync() 方法。提前致谢。
注意:下面的控制器有超过 50 个注入服务(我在下面展示了几个)。所以我不知道哪种方法也适合模拟这些服务?
控制器:
(function () {
appModule.controller('myController', [
'$scope', '$modalInstance', 'abp.services.app.property', 'abp.services.app.county', 'abp.services.app.propertyClass', 'abp.services.app.schoolDistrict'
function ($scope, $modalInstance, propertyService, countyService, propertyClassService, schoolDistrictService) {
vm.getAllCounties = function () {
countyService.getAllCountiesAsync().success(function (result) {
vm.counties = result.items;
});
};
vm.getAllCounties();
} ]);
})();
WebApi 方法:
public async Task<ListResultOutput<CountyListDto>> GetAllCountiesAsync()
{
var counties = await _countyRepository
.GetAllListAsync();
return new ListResultOutput<CountyListDto>(counties.OrderBy(o => o.Name).MapTo<List<CountyListDto>>());
}
【问题讨论】:
标签: angularjs unit-testing jasmine