我对单元测试很陌生。我有一个使用ngDialouge的角度服务 - 这是2个单选按钮是/否。
angular.module('jasminKarmaPoc1App')
.factory('fateLayingService', fateLayingService);
.....
var response = {}
response.AvoidPayment = function (playerDetails){
....
var prom = ngDialog.open(
{
template: 'scripts/decisionbox/fate-decision- modal-window.html',
controller: 'DecisionBoxController'
}
);
prom.closePromise.then(function (res) {
if (res.value === "1")
{
//***Below is the one I want to test -i.e. alert and updation of scope ****
//alert the message and update some related scope variables login
}
if (res.value === "2")
{
//**Below is the one I want to test -i.e. alert and updation of scope
//alert the message and update some related scope variables login
}
.....
return response()
现在我想单元测试消息并测试scope.msg是否根据对话框选择进行更新(Yes给出不同的msg和No给出不同的msg)。 如果我想测试那些消息,我需要模拟ngDialog以及他们的选择(是/否),但我对如何完全做到这一点感到困惑。任何帮助,将不胜感激。
答案 0 :(得分:0)
我不确定您是否要使用open或openConfirm。这是开放的
ngDialog = jasmine.createSpyObj('ngDialog', ['open']);
ngDialog.open.and.returnValue({
closePromise : {
then : function(callback) {
callback({value: 1});
}
}
});
/* Test with res.value = 1*/
response.AvoidPayment();