2016-03-26 12 views
0

Birim test için çok yeni. NgDialouge kullanan bir açısal servisim var - bu 2 radyo düğmesinin Evet/Hayır.Yasemin Karma ile ngDialogue için Evet/Hayır kararını alay Nasıl

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() 

Şimdi birim test mesajları ve scope.msg diyalog kutusu seçimine bağlı olarak güncellenen var mı testine istiyorum (Evet farklı msj verir ve No farklı msj verir). Eğer bu mesajları test etmek istersem, ngDialog ile seçimlerini yapmam gerekiyor (Evet/Hayır), ama tam olarak nasıl yapılacağı konusunda kafam karıştı. Herhangi bir yardım takdir edilecektir.

+0

http://jasmine.github.io/2.0/introduction.html#section-Spies:_ and.callFake size yardımcı olabilir bu. NgDialog ile çok aşina değil, ama casus kullanarak işlevi alay etmek muhtemelen işe yarayabilir. – TheyCallMeSam

+0

Bağlantı için teşekkürler – user2869612

cevap

0

Açık veya openConfirm kullanmak istediğinizden emin değilim. Burada açık

ngDialog = jasmine.createSpyObj('ngDialog', ['open']); 
 
ngDialog.open.and.returnValue({ 
 
\t closePromise : { 
 
\t \t then : function(callback) { 
 
\t \t \t callback({value: 1}); 
 
\t \t } 
 
\t } 
 
}); 
 

 

 
/* Test with res.value = 1*/ 
 
response.AvoidPayment();