lodash: Add unit tests. [jddalton]

Former-commit-id: 2c4c8e56bb4afaf19d4da520b2fa995b30251401
This commit is contained in:
John-David Dalton
2012-04-22 17:00:14 -04:00
parent 89f82359c1
commit 56b2d76eec
4 changed files with 157 additions and 99 deletions

View File

@@ -68,6 +68,66 @@
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.forEach');
(function() {
test('returns the collection', function() {
var collection = [1, 2, 3, 4];
equal(_.forEach(collection, Boolean), collection);
});
}());
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.initial');
(function() {
test('returns an empty collection for `n` of `0`', function() {
var array = [1, 2, 3, 4];
deepEqual(_.initial(array, 0), []);
});
}());
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.isNaN');
(function() {
test('returns `true` for `new Number(NaN)`', function() {
equal(_.isNaN(new Number(NaN)), true)
});
}());
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.reduceRight');
(function() {
test('should pass the correct `callback` arguments when iterating an object', function() {
var args,
object = { 'a': 'A', 'b': 'B', 'c': 'C' },
keys = _.keys(object);
_.reduceRight(object, function() {
args || (args = slice.call(arguments));
});
deepEqual(args, ['C', 'B', 'b', object]);
});
}());
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.size');
(function() {
test('should detect the size of a string value', function() {
equal(_.size('abc'), 3);
});
}());
/*--------------------------------------------------------------------------*/
// explicitly call `QUnit.start()` in a CLI environment
if (!window.document) {
QUnit.start();