我正在尝试编写文件上传的单元测试,但我无法满足以下条件以绕过验证。有人可以帮助我完成测试。
if($scope.selected.files == undefined || $scope.selected.files == null || $scope.selected.files.length == 0){
$window.alert("Please select upload file.");
return;
}
我想满足上述条件,因此不应显示警告信息。
我尝试了以下测试,但没有通过长度验证。
it("should validate the selected file size.",
function() {
debugger
$scope.fileSelection = true;
var file= {
"lastModified": 1438583972000,
"lastModifiedDate": "2015-08-03T06:39:32.000Z",
"name": "gitignore_global.txt",
"size": 236,
"type": "text/plain",
"data": "data:text/plain;base64,DQojaWdub3JlIHRodW1ibmFpbHMgY3JlYXRlZCBieSB3aW5kb3dz…xoDQoqLmJhaw0KKi5jYWNoZQ0KKi5pbGsNCioubG9nDQoqLmRsbA0KKi5saWINCiouc2JyDQo="
}
var files = [];
files[0] = { file,fileType:{id:'1'}};
$scope.selected = {files};
spyOn(window, 'alert');
createController();
$scope.transferFile();
expect(window.alert).toHaveBeenCalledWith("The selected upload file is empty. Please upload the valid file.");
});