From ecb17347328ee1097b4e3f4d714974cc5f580ad9 Mon Sep 17 00:00:00 2001 From: micha Date: Fri, 31 Oct 2014 08:39:00 +0100 Subject: [PATCH] Added unit test for Issue #378 --- src/loading.js | 2 +- test/src/loading.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/loading.js b/src/loading.js index b8dd92f7..14137a89 100644 --- a/src/loading.js +++ b/src/loading.js @@ -392,7 +392,7 @@ function fetchQueue(dataObj, options, $super) { var fetchQueue = dataObj.fetchQueue; dataObj.fetchQueue.push({ - // Individual requests can only fail individually. Success willl always occur via the + // Individual requests can only fail individually. Success will always occur via the // normal xhr path aborted: function() { var index = _.indexOf(fetchQueue, this); diff --git a/test/src/loading.js b/test/src/loading.js index d1132b61..0c6dd2fe 100644 --- a/test/src/loading.js +++ b/test/src/loading.js @@ -68,6 +68,24 @@ describe('loading', function() { expect(endSpy.callCount).to.equal(0); }); + + it("calls the success handler on the first fetch call when the fetch operation is synchronous", function () { + var collection = new (Thorax.Collection.extend({ + url: "test" + })); + + var syncStub = sinon.stub(Backbone, "sync", function (method, model, options) { + options.success(model, [ { name: "Test", value: "Value" } ], options) + }); + + var successSpy = sinon.spy(); + + collection.fetch({ success: successSpy }); + syncStub.restore(); + + expect(successSpy.callCount).to.equal(1); + }); + // for jQuery or Zepto when built with Deferred if ($.when) { it("returns a promise", function() {