Skip to content

Commit

Permalink
listen for invalid, not error
Browse files Browse the repository at this point in the history
  • Loading branch information
robrobbins committed Nov 11, 2014
1 parent 40ea6f1 commit 51d076c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions test/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,9 @@
});

test("#861, adding models to a collection which do not pass validation, with validate:true", function() {
// 'error' is not triggered -- 'invalid' is
var invalidCalled = false;

var Model = Backbone.Model.extend({
validate: function(attrs) {
if (attrs.id == 3) return "id can't be 3";
Expand All @@ -708,10 +711,13 @@
});

var collection = new Collection;
collection.on("error", function() { ok(true); });
collection.on("invalid", function() { invalidCalled = true; });

collection.add([{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, {id: 6}], {validate:true});
deepEqual(collection.pluck('id'), [1, 2, 4, 5, 6]);
deepEqual(collection.pluck("id"), [1, 2, 4, 5, 6]);

// assure that the invalid callback was called
ok(invalidCalled);
});

test("Invalid models are discarded with validate:true.", 5, function() {
Expand Down

0 comments on commit 51d076c

Please sign in to comment.