mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-22 05:18:17 -05:00
adding test for falsy comparators (#1342)
This commit is contained in:
@@ -548,7 +548,7 @@
|
||||
var Collection = Backbone.Collection = function(models, options) {
|
||||
options || (options = {});
|
||||
if (options.model) this.model = options.model;
|
||||
if (typeof options.comparator !== 'undefined') this.comparator = options.comparator;
|
||||
if (options.comparator !== undefined) this.comparator = options.comparator;
|
||||
this._reset();
|
||||
this.initialize.apply(this, arguments);
|
||||
if (models) this.reset(models, {silent: true, parse: options.parse});
|
||||
|
||||
@@ -599,4 +599,17 @@ $(document).ready(function() {
|
||||
ok(!collection.get('undefined'));
|
||||
});
|
||||
|
||||
test("Collection: falsy comparator", function(){
|
||||
var Col = Backbone.Collection.extend({
|
||||
comparator: function(model){ return model.id; }
|
||||
});
|
||||
var col = new Col([{id: 2}, {id: 1}], {
|
||||
comparator: false
|
||||
});
|
||||
var otherCol = new Col([{id: 2}, {id: 1}]);
|
||||
raises(function(){ col.sort() });
|
||||
equal(col.first().id, 2);
|
||||
equal(otherCol.first().id, 1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user