Add more lodashBadShim tests.

This commit is contained in:
John-David Dalton
2013-12-02 01:39:14 -08:00
parent ff47152187
commit 9e42f70e5f

View File

@@ -353,22 +353,21 @@
} }
}); });
test('avoids overwritten native methods', 6, function() { test('avoids overwritten native methods', 7, function() {
function Foo() {} function Foo() {}
function message(methodName) { function message(methodName) {
return '`_.' + methodName + '` should avoid overwritten native methods'; return '`_.' + methodName + '` should avoid overwritten native methods';
} }
var object = { 'a': true }; var object = { 'a': true };
if (lodashBadShim) { if (lodashBadShim) {
try { try {
actual = lodashBadShim.isArray([]); actual = [lodashBadShim.isArray([]), lodashBadShim.isArray({ 'length': 0 })];
} catch(e) { } catch(e) {
actual = null; actual = null;
} }
ok(actual, message('Array.isArray')); deepEqual(actual, [true, false], message('Array.isArray'));
try { try {
actual = lodashBadShim.now(); actual = lodashBadShim.now();
@@ -378,11 +377,12 @@
ok(typeof actual == 'number', message('Date.now')); ok(typeof actual == 'number', message('Date.now'));
try { try {
actual = lodashBadShim.create(Foo.prototype, object); actual = [lodashBadShim.create(Foo.prototype, object), lodashBadShim.create()];
} catch(e) { } catch(e) {
actual = null; actual = null;
} }
ok(actual instanceof Foo, message('Object.create')); ok(actual[0] instanceof Foo, message('Object.create'));
deepEqual(actual[1], {}, message('Object.create'));
try { try {
var actual = lodashBadShim.bind(function() { return this.a; }, object)(); var actual = lodashBadShim.bind(function() { return this.a; }, object)();
@@ -399,14 +399,14 @@
deepEqual(actual, [true, false], message('Object.getPrototypeOf')); deepEqual(actual, [true, false], message('Object.getPrototypeOf'));
try { try {
actual = lodashBadShim.keys(object); actual = [lodashBadShim.keys(object), lodashBadShim.keys()];
} catch(e) { } catch(e) {
actual = null; actual = null;
} }
deepEqual(actual, ['a'], message('Object.keys')); deepEqual(actual, [['a'], []], message('Object.keys'));
} }
else { else {
skipTest(6); skipTest(7);
} }
}); });
}()); }());
@@ -5432,9 +5432,9 @@
asyncTest('should return the number of milliseconds that have elapsed since the Unix epoch', 2, function() { asyncTest('should return the number of milliseconds that have elapsed since the Unix epoch', 2, function() {
var stamp = +new Date, var stamp = +new Date,
actual = _.now(); actual = _.now();
ok(actual >= stamp); ok(actual >= stamp);
if (!(isRhino && isModularize)) { if (!(isRhino && isModularize)) {
setTimeout(function() { setTimeout(function() {
ok(_.now() > actual); ok(_.now() > actual);