From b1575f72a608ff3b04cfeadd76c180c16acd396f Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Thu, 31 Jan 2013 13:34:35 -0500 Subject: [PATCH] adding tests for error event on all sync methods --- test/collection.js | 9 +++++++++ test/model.js | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/test/collection.js b/test/collection.js index 4dbf5b88..d0611538 100644 --- a/test/collection.js +++ b/test/collection.js @@ -394,6 +394,15 @@ $(document).ready(function() { equal(this.syncArgs.options.parse, false); }); + test("fetch with an error response triggers an error event", 1, function () { + var collection = new Backbone.Collection(); + collection.on('error', function () { + ok(true); + }); + collection.sync = function (method, model, options) { options.error(); }; + collection.fetch(); + }); + test("ensure fetch only parses once", 1, function() { var collection = new Backbone.Collection; var counter = 0; diff --git a/test/model.js b/test/model.js index 7f031322..f0a2fe4a 100644 --- a/test/model.js +++ b/test/model.js @@ -418,6 +418,19 @@ $(document).ready(function() { ok(_.isEqual(this.syncArgs.model, doc)); }); + test("save, fetch, destroy triggers error event when an error occurs", 3, function () { + var model = new Backbone.Model(); + model.on('error', function () { + ok(true); + }); + model.sync = function (method, model, options) { + options.error(); + }; + model.save({data: 2, id: 1}); + model.fetch(); + model.destroy(); + }); + test("save with PATCH", function() { doc.clear().set({id: 1, a: 1, b: 2, c: 3, d: 4}); doc.save();