如何为以下角度函数编写单元测试用例
how to write a unit test case for the following angular function
如何为以下角度函数编写单元测试用例。我是因果报应和茉莉花的新手。函数,还必须测试if语句内部的window.open。
$rootScope.getStandardMapPDF = function (mt, g, u, m)
{
var menuTitle = mt.trim();
var grade = g.trim();
var unit = u.trim();
var module = m.trim();
/*---->Getting the Grade, Unit and Module wise Help files <-------*/
if ($.isEmptyObject($rootScope.StandardMapFiles)) {
$rootScope.StandardMapFiles = DataProvider.StandardHelpMaster;
}
var obj = $rootScope.StandardMapFiles;
for (var i = 0; i < obj.length; i++) {
if (obj[i].Grade.toLowerCase().indexOf(grade.toLowerCase()) != -1 && obj[i].Unit.toLowerCase().indexOf(unit.toLowerCase()) != -1 && obj[i].Module.toLowerCase().indexOf(module.toLowerCase()) != -1 && obj[i].MenuTitle.toLowerCase() == menuTitle.toLowerCase()) {
if (obj[i].FileType.toLowerCase() == 'pdf') {
var path = 'Resources/StandardMappings/' + obj[i].FileName.trim() + '.pdf';
//var path = '/fs/oleshare/ole-mygen/StandardMappings/' + obj[i].FileName.trim() + '.pdf';
$window.open(path, '_blank');
}
else if (obj[i].FileType.toLowerCase() == 'video') {
var path = 'Resources/Video/' + obj[i].FileName.split('.')[0].trim() + '.htm';
$window.open(path, '_blank');
}
}
}
};
以下是如何编写测试的基本概述:
(function() {
describe('your.controller.name.js', function() {
var $rootScope, $window;
// Init
beforeEach(module('your-app-name'));
beforeEach(inject(function(_$rootScope_,_$window_) {
$rootScope = _$rootScope_;
$window = _$window_;
}));
// Spies
beforeEach(function() {
spyOn($window,'open');
});
it('should be defined', function() {
expect($rootScope.getStandardMapPDF).toBeDefined();
});
describe('$rootScope.getStandardMapPDF', function() {
beforeEach(function() {
$rootScope.getStandardMapPDF()
});
it('should call $window.open', function() {
expect($window.open).toHaveBeenCalled();
});
});
}());
为什么要将函数附加到$rootScope
?
相关文章:
- AngularJS指令单元测试中未定义的函数
- 如何为以下角度函数编写单元测试用例
- 如何使用图表包装函数有条件地格式化谷歌可视化表单元格
- 如何在JavaScript中对箭头函数进行单元测试
- 在http服务单元测试中使用request-js时,chai.request不是一个函数
- 为什么谷歌应用程序的电子表格setValue函数没有在单元格中设置值
- Handsontable :如何在渲染函数中更改单元格值
- 如何对调用getJSON的javascript函数进行单元测试
- 如何在JS/HTML中将函数输出发送到表单元格
- AngluarJS单元测试-未定义不是函数
- 从FORM访问HTML元素的JavaScript函数的单元测试用例
- 如何在另一个java脚本函数中访问java脚本中动态html表中单元格的动态赋值
- 因果报应单元测试'未定义'不是函数错误
- 谷歌应用程序脚本:;范围不是函数,它是对象;尝试在单元格中放置注释时出错
- 没有返回类型的函数的Javascript单元测试
- JS Monad 单元函数
- 在对揭示模块进行单元测试时,如何存根私有函数
- AngularJS私有函数单元测试混乱
- 未定义不是函数:单元测试护照身份验证自定义回调
- 使用函数单元测试弹出窗口