Update Underscore/Backbone tests and make them passable.

This commit is contained in:
John-David Dalton
2015-08-08 16:52:47 -07:00
parent de5c2b906e
commit bd9b38665d
13 changed files with 843 additions and 550 deletions

View File

@@ -977,16 +977,19 @@
// normal circumstances, as the set will maintain sort order as each item
// is added.
sort: function(options) {
if (!this.comparator) throw new Error('Cannot sort a set without a comparator');
var comparator = this.comparator;
if (!comparator) throw new Error('Cannot sort a set without a comparator');
options || (options = {});
// Run sort based on type of `comparator`.
if (_.isString(this.comparator) || this.comparator.length === 1) {
this.models = this.sortBy(this.comparator, this);
} else {
this.models.sort(_.bind(this.comparator, this));
}
var length = comparator.length;
if (_.isFunction(comparator)) comparator = _.bind(comparator, this);
// Run sort based on type of `comparator`.
if (length === 1 || _.isString(comparator)) {
this.models = this.sortBy(comparator);
} else {
this.models.sort(comparator);
}
if (!options.silent) this.trigger('sort', this, options);
return this;
},
@@ -1144,8 +1147,8 @@
// right here:
var collectionMethods = { forEach: 3, each: 3, map: 3, collect: 3, reduce: 4,
foldl: 4, inject: 4, reduceRight: 4, foldr: 4, find: 3, detect: 3, filter: 3,
select: 3, reject: 3, every: 3, all: 3, some: 3, any: 3, include: 2,
contains: 2, invoke: 0, max: 3, min: 3, toArray: 1, size: 1, first: 3,
select: 3, reject: 3, every: 3, all: 3, some: 3, any: 3, include: 3, includes: 3,
contains: 3, invoke: 0, max: 3, min: 3, toArray: 1, size: 1, first: 3,
head: 3, take: 3, initial: 3, rest: 3, tail: 3, drop: 3, last: 3,
without: 0, difference: 0, indexOf: 3, shuffle: 1, lastIndexOf: 3,
isEmpty: 1, chain: 1, sample: 3, partition: 3, groupBy: 3, countBy: 3,

View File

@@ -625,24 +625,26 @@
test("Underscore methods", 19, function() {
equal(col.map(function(model){ return model.get('label'); }).join(' '), 'a b c d');
equal(col.any(function(model){ return model.id === 100; }), false);
equal(col.any(function(model){ return model.id === 0; }), true);
equal(col.some(function(model){ return model.id === 100; }), false);
equal(col.some(function(model){ return model.id === 0; }), true);
equal(col.indexOf(b), 1);
equal(col.size(), 4);
equal(col.rest().length, 3);
ok(!_.include(col.rest(), a));
ok(_.include(col.rest(), d));
ok(!_.includes(col.rest(), a));
ok(_.includes(col.rest(), d));
ok(!col.isEmpty());
ok(!_.include(col.without(d), d));
equal(col.max(function(model){ return model.id; }).id, 3);
equal(col.min(function(model){ return model.id; }).id, 0);
deepEqual(col.chain()
ok(!_.includes(col.without(d), d));
var wrapped = col.chain();
equal(wrapped.map('id').max().value(), 3);
equal(wrapped.map('id').min().value(), 0);
deepEqual(wrapped
.filter(function(o){ return o.id % 2 === 0; })
.map(function(o){ return o.id * 2; })
.value(),
[4, 0]);
[4, 0]);
deepEqual(col.difference([c, d]), [a, b]);
ok(col.include(col.sample()));
ok(col.includes(col.sample()));
var first = col.first();
deepEqual(col.groupBy(function(model){ return model.id; })[first.id], [first]);
deepEqual(col.countBy(function(model){ return model.id; }), {0: 1, 1: 1, 2: 1, 3: 1});
@@ -676,8 +678,8 @@
deepEqual(coll.partition({a: 4})[1], _.without(coll.models, model));
deepEqual(coll.map({a: 2}), [false, true, false, false]);
deepEqual(coll.map('a'), [1, 2, 3, 4]);
deepEqual(coll.max('a'), model);
deepEqual(coll.min('e'), model);
deepEqual(coll.sortBy('a')[3], model);
deepEqual(coll.sortBy('e')[0], model);
deepEqual(coll.countBy({a: 4}), {'false': 3, 'true': 1});
deepEqual(coll.countBy('d'), {'undefined': 4});
});
@@ -1175,7 +1177,7 @@
var Model = Backbone.Model.extend({});
var Collection = Backbone.Collection.extend({
model: Model,
parse: function (res) { return _.pluck(res.models, 'model'); }
parse: function (res) { return _.map(res.models, 'model'); }
});
var model = new Model({id: 1});
var collection = new Collection(model);

View File

@@ -1,6 +1,4 @@
$('body').append(
'<div id="qunit"></div>' +
'<div id="qunit-fixture">' +
'<div id="testElement"><h1>Test</h1></div>' +
'</div>'
);
'<div id="qunit-fixture"></div>'
);

View File

@@ -5,6 +5,10 @@
module("Backbone.View", {
setup: function() {
$('#qunit-fixture').append(
'<div id="testElement"><h1>Test</h1></div>'
);
view = new Backbone.View({
id : 'test-view',
className : 'test-view',