2012-04-11 11 views

答えて

0

これは、以下の例の方法を使用して実現できます。 、以下のコードはフェッチコールを傍受して戻ります。コールはサーバーに届きません。サーバー側のエミュレーションが必要な場合は、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. 

     }); 
    }); 
関連する問題