Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

Success handler of fetch is not called when response is synchronous (and fetchQueue is empty) #378

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions test/src/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down