mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Tests for our _.each patch
This commit is contained in:
1
packages/underscore-tests/.gitignore
vendored
Normal file
1
packages/underscore-tests/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.build*
|
||||
45
packages/underscore-tests/each_test.js
Normal file
45
packages/underscore-tests/each_test.js
Normal file
@@ -0,0 +1,45 @@
|
||||
Tinytest.add("underscore - each", function (test) {
|
||||
// arrays
|
||||
_.each([42], function (val, index) {
|
||||
test.equal(index, 0);
|
||||
test.equal(val, 42);
|
||||
});
|
||||
|
||||
// objects with 'length' field aren't treated as arrays
|
||||
_.each({length: 42}, function (val, key) {
|
||||
test.equal(key, 'length');
|
||||
test.equal(val, 42);
|
||||
});
|
||||
|
||||
// The special 'arguments' variable is treated as an
|
||||
// array
|
||||
(function () {
|
||||
_.each(arguments, function (val, index) {
|
||||
test.equal(index, 0);
|
||||
test.equal(val, 42);
|
||||
});
|
||||
})(42);
|
||||
|
||||
// An object with a 'callee' field isn't treated as arguments
|
||||
_.each({callee: 42}, function (val, key) {
|
||||
test.equal(key, 'callee');
|
||||
test.equal(val, 42);
|
||||
});
|
||||
|
||||
// An object with a 'callee' field isn't treated as arguments
|
||||
_.each({length: 4, callee: 42}, function (val, key) {
|
||||
if (key === 'callee')
|
||||
test.equal(val, 42);
|
||||
else if (key === 'length')
|
||||
test.equal(val, 4);
|
||||
else
|
||||
test.fail({message: 'unexpected key: ' + key});
|
||||
});
|
||||
|
||||
|
||||
// NOTE: An object with a numberic 'length' field *and* a function
|
||||
// 'callee' field will be treated as an array in IE. This may or may
|
||||
// not be fixable, but isn't a big deal since: (1) 'callee' is a
|
||||
// pretty rare key, and (2) JSON objects can't have functions
|
||||
// anyways, which is the main use-case for _.each.
|
||||
});
|
||||
10
packages/underscore-tests/package.js
Normal file
10
packages/underscore-tests/package.js
Normal file
@@ -0,0 +1,10 @@
|
||||
Package.describe({
|
||||
// These tests can't be directly in the underscore packages since
|
||||
// Tinytest depends on underscore
|
||||
summary: "Tests for the underscore package"
|
||||
});
|
||||
|
||||
Package.on_test(function (api) {
|
||||
api.use(['tinytest', 'underscore']);
|
||||
api.add_files('each_test.js');
|
||||
});
|
||||
@@ -81,7 +81,7 @@
|
||||
// there isn't any inspectable "Arguments" type.
|
||||
if (!_isArguments(arguments)) {
|
||||
_isArguments = function (obj) {
|
||||
return !!(obj && hasOwnProperty.call(obj, 'callee'));
|
||||
return !!(obj && hasOwnProperty.call(obj, 'callee') && typeof obj.callee === 'function');
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user