我有一个函数,是一个聚合web组件的自定义函数。
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) || []);
}此函数返回数组或数组为空。
我想测试它,我正在使用web-component-tester,我使用gulp test:local运行测试。我知道我需要嘲笑e.model.__data__.date.data.id,但我不知道怎么做
发布于 2015-11-21 22:10:56
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');
});https://stackoverflow.com/questions/33778394
复制相似问题