2015-11-18 22 views
0

我有一個功能,是聚合物網頁組件定製的功能。如何用聚合物進行模擬測試

getListDedications: function(e){ 
 
      var idDate = e.model.__data__.date.data.id; 
 
      var checkId = function(element){ 
 
       return element.id == idDate; 
 
      }; 
 
      var responseID = this.dedications.filter(checkId); 
 
      this.data = JSON.stringify(responseID[0].entries) || []; 
 
      console.log(JSON.stringify(responseID[0].entries) || []); 
 
    }
該函數返回一個數組或數組爲空。

我想測試它,我使用的是網絡組件測試儀,並使用gulp test:local運行測試。 我知道我需要模擬e.model.__data__.date.data.id,但我不知道如何

回答

0

Web組件測試儀現在捆綁了sinon和sinon-chai。

你不說什麼e.model._data__.date.date.id是。顯然,如果它只是數據,那麼設置它,然後用a參數調用getListModifications。然而,如果它的功能,然後使用與sinon stub(或間諜)

var sandbox; 
beforeEach(function(){ 
    sandbox = sinon.sandbox.create(); 
}); 
afterEach(function(){ 
    sandbox.restore(); 
}); 
it('should ...',function(){ 
    var e = sandbox.stub().returns('whatever data you want'); 
    var answer = getListDedications(e); 
    expect(answer).to.be.an('Array'); 
}); 
相關問題