如何使用聚合物

时间:2015-11-18 11:05:46

标签: javascript testing mocking polymer

我有一个功能,是聚合物网络组件定制的功能。



    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,但我不知道如何

1 个答案:

答案 0 :(得分:0)

Web组件测试器现在捆绑了sinon和sinon-chai。

你没有说e.model._data__.date.date.id是什么。显然,如果它只是数据,你可以设置它,然后使用a参数调用getListModifications。但是,如果它是一个函数,则使用sinon stub(或spy)和

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');
});
相关问题