0
バックボーンコレクションがあり、いくつかのパラメータを.fetch({data:{gender: 'male'}})に渡す必要があります。ジャスミンを使ってパラメータを渡す方法はありますか?バックスンジャスを使ったジャスミンテスト(パラメータが渡された場合)
ありがとうございました
バックボーンコレクションがあり、いくつかのパラメータを.fetch({data:{gender: 'male'}})に渡す必要があります。ジャスミンを使ってパラメータを渡す方法はありますか?バックスンジャスを使ったジャスミンテスト(パラメータが渡された場合)
ありがとうございました
これは、以下の例の方法を使用して実現できます。 、以下のコードはフェッチコールを傍受して戻ります。コールはサーバーに届きません。サーバー側のエミュレーションが必要な場合は、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.
});
});