mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Add more false values unit tests for _.size and "Arrays"/"Collections" methods.
Former-commit-id: 475941321404ceec4eabb56fb9ee10855a653e12
This commit is contained in:
34
test/test.js
34
test/test.js
@@ -638,11 +638,12 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should allow a falsey `object` argument', function() {
|
test('should allow a falsey `object` argument', function() {
|
||||||
|
var fn = _.size;
|
||||||
try {
|
try {
|
||||||
var actual = [_.size(), _.size(null), _.size(false), _.size(0)];
|
var actual = [fn(), fn(undefined), fn(null), fn(false), fn(0)];
|
||||||
} catch(e) { }
|
} catch(e) { }
|
||||||
|
|
||||||
deepEqual(actual, [0, 0, 0, 0]);
|
deepEqual(actual, [0, 0, 0, 0, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work with `arguments` objects (test in IE < 9)', function() {
|
test('should work with `arguments` objects (test in IE < 9)', function() {
|
||||||
@@ -906,9 +907,15 @@
|
|||||||
'zip',
|
'zip',
|
||||||
'zipObject'
|
'zipObject'
|
||||||
], function(methodName) {
|
], function(methodName) {
|
||||||
var pass = true;
|
var fn = _[methodName],
|
||||||
|
pass = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_[methodName]();
|
fn();
|
||||||
|
fn(undefined);
|
||||||
|
fn(null);
|
||||||
|
fn(false);
|
||||||
|
fn(0);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
pass = false;
|
pass = false;
|
||||||
}
|
}
|
||||||
@@ -938,12 +945,23 @@
|
|||||||
'some',
|
'some',
|
||||||
'toArray'
|
'toArray'
|
||||||
], function(methodName) {
|
], function(methodName) {
|
||||||
var pass = true;
|
var fn = _[methodName],
|
||||||
|
identity = _.identity,
|
||||||
|
pass = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (/^(?:contains|toArray)$/.test(methodName)) {
|
if (/^(?:contains|toArray)$/.test(methodName)) {
|
||||||
_[methodName](null);
|
fn();
|
||||||
} else {
|
fn(undefined);
|
||||||
_[methodName](null, _.identity);
|
fn(null);
|
||||||
|
fn(false);
|
||||||
|
fn(0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fn(undefined, identity);
|
||||||
|
fn(null, identity);
|
||||||
|
fn(false, identity);
|
||||||
|
fn(0, identity);
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
pass = false;
|
pass = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user