lodash: Cleanup compiled code and check for a toArray method on objects before others in _.toArray. [jddalton]

Former-commit-id: 9fdde9bbbecd0480e7d3d6674b43cea0810d2aed
This commit is contained in:
John-David Dalton
2012-04-23 10:48:08 -04:00
parent 9169039974
commit f58386b391
4 changed files with 154 additions and 123 deletions

View File

@@ -128,6 +128,26 @@
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.toArray');
(function() {
var args = arguments;
test('should call custom `toArray` method of an array', function() {
var array = [1, 2, 3];
array.toArray = function() { return [3, 2, 1] };
deepEqual(_.toArray(array), [3, 2, 1]);
});
test('should treat array-like-objects like arrays', function() {
var object = { '0': 'a', '1': 'b', '2': 'c', 'length': 3 };
deepEqual(_.toArray(object), ['a', 'b', 'c']);
deepEqual(_.toArray(args), [1, 2, 3]);
});
}(1, 2, 3));
/*--------------------------------------------------------------------------*/
// explicitly call `QUnit.start()` in a CLI environment
if (!window.document) {
QUnit.start();