2014-09-05 33 views
1

在我的測試中,我手動實例化組件並將其附加到DOM。出於某種原因,我似乎無法使用點擊操作觸發該組件上的操作,但如果我要手動調用操作上的「發送」,那麼它就可以工作。這裏是一個jsbin測試鏈接:http://jsbin.com/copum/1/在測試時不能觸發組件中的動作

 //THIS DOESN'T WORK 
     click('button.click-me'); 
     andThen(function(){ 
      expect(find('#click-status').length).to.be(1);    
     }); 

     /* 
     //THIS WORKS THOUGH 
     Ember.run(function(){ 
      documentCollection.send('clickMe'); 
     }); 
     andThen(function(){ 
      expect(find('#click-status').length).to.be(1);    
     });    
     */ 

好像燼無法找到由於某種原因,動作相關的DOM。任何方式,我可以使事情與點擊事件?

在此先感謝。

回答

1

你只是缺少在您的測試:)

這個現在通過頂部的訪問,如你所期望

it("should show the text when clicking the button - using click", function() { 
     visit('/'); 
     click('button.click-me'); 
     andThen(function(){ 
      expect(find('#click-status').length).to.be(1);    
     }); 
    }); 
+0

拍攝就是它。感謝@Toran找出答案。 – 2014-09-09 13:07:09

0

另外,如果你不想打電話給visit('/')做工作,你可以手動創建一個Ember.EventDispatcher,只要不要忘記完成後就銷燬它。

it("should show the text when clicking the button - using click", function() { 
    dispatcher = Ember.EventDispatcher.create(); 
    dispatcher.setup(); 
    click('button.click-me'); 
    andThen(function(){ 
     expect(find('#click-status').length).to.be(1);    
     Ember.run(function(){ 
      dispatcher.destroy(); 
     }); 
    }); 
}); 
相關問題