2013-09-23 41 views
2

我正在嘗試編寫一個Jasmine測試來覆蓋Twitter Boostrap模式對話框。當調試器行被註釋掉時,測試失敗。它在調試器暫停處理時通過,我繼續。我相信Bootstrap模式中的轉換引發了這個問題,因爲在我預期的調用時模式對話框還沒有在DOM中。爲Jasmine測試禁用引導轉換

如何在測試期間禁用轉換?

感謝

describe("test dialog", function(){ 
    it("when cancel button is clicked", function() { 
     spyOn(MyTestObj, 'myMethod') 

     $("#cancelButton").click(); 

     debugger; 

     expect($(".bootbox-body")).toHaveText("Are you sure you want to cancel?") 

     $('.modal-footer button[data-bb-handler="Yes"]').click(); 

     expect(MyTestObj.myMethod).toHaveBeenCalledWith("123") 
    }) 
}) 

由於震動,您的解決方案的工作太棒了!這是我的工作測試:

describe("test dialog", function(){ 
     it("when cancel button is clicked", function() { 
      spyOn(MyTestObj, 'myMethod') 

      $("#cancelButton").click(); 

      waitsFor(function() { 
       return $(".bootbox-body").is(":visible"); 
      }, "Element did not show up", 1000); 

      runs(function() { 
       expect($(".bootbox-body")).toHaveText("Are you sure you want to cancel?") 
       $('.modal-footer button[data-bb-handler="Yes"]').click(); 

       expect(MyTestObj.myMethod).toHaveBeenCalledWith("123") 
      }) 
     })  
    }) 

回答