Backbone.js BackboneJS使用jasmine测试是否传递参数以获取
我有一个主干集合,需要将一些参数传递给.fetch({data:{gender:'male'})。有没有办法用jasmine测试参数是否通过Backbone.js BackboneJS使用jasmine测试是否传递参数以获取,backbone.js,jasmine,Backbone.js,Jasmine,我有一个主干集合,需要将一些参数传递给.fetch({data:{gender:'male'})。有没有办法用jasmine测试参数是否通过 提前感谢您可以使用下面示例中的方法来实现这一点。 请注意,,下面的代码将截获获取调用并返回,调用将不会到达服务器。如果希望进行服务器端仿真,则需要使用Sinon或其他类似方法 describe("People collection" function() { var people = Backbone.Collection.exte
提前感谢您可以使用下面示例中的方法来实现这一点。 请注意,,下面的代码将截获获取调用并返回,调用将不会到达服务器。如果希望进行服务器端仿真,则需要使用Sinon或其他类似方法
describe("People collection" function() {
var people = Backbone.Collection.extend({
// ...
});
function searchPeople(people, data ) {
people.fetch(data);
}
it("must verify the fetch parameters!", function(){
var param = {data : {gender : 'male'}};
// Set up the spy.
spyOn(people, 'fetch').andReturn(); // Warning: this makes the call synchronous, Fetch actually won't go through!
// Now perform the operation that would invoke Collection.fetch.
searchPeople(people, param);
expect(people.fetch).toHaveBeenCalled(); // Verifies the fetch was actually called.
expect(people.fetch).toHaveBeenCalledWith(param); // Verifies that the fetch was called with specified param.
});
});