【发布时间】:2015-10-21 21:20:08
【问题描述】:
我正在测试具有功能的主干视图:
attachSelect: function(id, route) {
console.log(id);
console.log(route);
this.$(id).select2({
ajax: {
url: route,
dataType: 'json',
results: function(data) {
var results = _.map(data, function(item) {
return {
id: item.id,
text: item.title
};
});
return {
results: results
};
},
cache: true
}
});
}
我需要重写(模拟)这个函数,看起来像:
attachSelect: function(id, route) {
console.log(id);
console.log(route);
}
如何做到这一点?
【问题讨论】:
-
这取决于您的测试设置。您可以在创建后覆盖视图方法。喜欢
this.someView.attachSelect = function (){};
标签: javascript backbone.js mocha.js sinon