mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Add more bad shim tests.
This commit is contained in:
@@ -17,7 +17,16 @@
|
|||||||
<div id="qunit"></div>
|
<div id="qunit"></div>
|
||||||
<div id="exports"></div>
|
<div id="exports"></div>
|
||||||
<script>
|
<script>
|
||||||
// set a bad shim
|
// set bad shims
|
||||||
|
Array._isArray = Array.isArray;
|
||||||
|
Array.isArray = function() { return false; };
|
||||||
|
|
||||||
|
Function.prototype._bind = Function.prototype.bind;
|
||||||
|
Function.prototype.bind = function() { return function() {}; };
|
||||||
|
|
||||||
|
Object._defineProperty = Object.defineProperty;
|
||||||
|
Object.defineProperty = function() {};
|
||||||
|
|
||||||
Object._keys = Object.keys;
|
Object._keys = Object.keys;
|
||||||
Object.keys = function() { return []; };
|
Object.keys = function() { return []; };
|
||||||
|
|
||||||
@@ -28,7 +37,16 @@
|
|||||||
// store Lo-Dash to test for bad shim detection
|
// store Lo-Dash to test for bad shim detection
|
||||||
var lodashBadShim = window._;
|
var lodashBadShim = window._;
|
||||||
|
|
||||||
// restore nativeKeys
|
// restore native methods
|
||||||
|
Array.isArray = Array._isArray;
|
||||||
|
delete Array._isArray;
|
||||||
|
|
||||||
|
Function.prototype.bind = Function.prototype._bind;
|
||||||
|
delete Function.prototype._bind;
|
||||||
|
|
||||||
|
Object.defineProperty = Object._defineProperty;
|
||||||
|
delete Object._defineProperty;
|
||||||
|
|
||||||
Object.keys = Object._keys;
|
Object.keys = Object._keys;
|
||||||
delete Object._keys;
|
delete Object._keys;
|
||||||
|
|
||||||
|
|||||||
28
test/test.js
28
test/test.js
@@ -255,10 +255,30 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('avoids overwritten native methods', function() {
|
test('avoids overwritten native methods', function() {
|
||||||
|
function message(methodName) {
|
||||||
|
return '`_.' + methodName + '` should avoid overwritten native methods';
|
||||||
|
}
|
||||||
|
|
||||||
|
var object = { 'a': true };
|
||||||
|
|
||||||
if (document) {
|
if (document) {
|
||||||
notDeepEqual(lodashBadShim.keys({ 'a': 1 }), []);
|
try {
|
||||||
} else {
|
var actual = lodashBadShim.bind(function() { return this.a; }, object)();
|
||||||
skipTest();
|
} catch(e) { }
|
||||||
|
ok(actual, message('bind'));
|
||||||
|
|
||||||
|
try {
|
||||||
|
actual = lodashBadShim.isArray([]);
|
||||||
|
} catch(e) { }
|
||||||
|
ok(actual, message('isArray'));
|
||||||
|
|
||||||
|
try {
|
||||||
|
actual = lodashBadShim.keys(object);
|
||||||
|
} catch(e) { }
|
||||||
|
deepEqual(actual, ['a'], message('keys'));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest(3);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
@@ -4437,7 +4457,7 @@
|
|||||||
_.forEach(falsey, function(value, index) {
|
_.forEach(falsey, function(value, index) {
|
||||||
try {
|
try {
|
||||||
actual.push(index ? func(value) : func());
|
actual.push(index ? func(value) : func());
|
||||||
} catch(e) { console.log(e)}
|
} catch(e) { }
|
||||||
});
|
});
|
||||||
|
|
||||||
deepEqual(actual, expected);
|
deepEqual(actual, expected);
|
||||||
|
|||||||
Reference in New Issue
Block a user