mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Add bad shim tests for String#contains and remove those for Function#bind as we don't use native bind.
This commit is contained in:
@@ -29,9 +29,6 @@
|
|||||||
Date._now = Date.now;
|
Date._now = Date.now;
|
||||||
Date.now = function() {};
|
Date.now = function() {};
|
||||||
|
|
||||||
Function.prototype._bind = Function.prototype.bind;
|
|
||||||
Function.prototype.bind = function() { return function() {}; };
|
|
||||||
|
|
||||||
Object._create = Object.create;
|
Object._create = Object.create;
|
||||||
Object.create = function() {};
|
Object.create = function() {};
|
||||||
|
|
||||||
@@ -44,6 +41,9 @@
|
|||||||
Object._keys = Object.keys;
|
Object._keys = Object.keys;
|
||||||
Object.keys = function() {};
|
Object.keys = function() {};
|
||||||
|
|
||||||
|
String.prototype._contains = String.prototype.contains;
|
||||||
|
String.prototype.contains = function() {};
|
||||||
|
|
||||||
window.WinRTError = Error;
|
window.WinRTError = Error;
|
||||||
|
|
||||||
document._createDocumentFragment = document.createDocumentFragment;
|
document._createDocumentFragment = document.createDocumentFragment;
|
||||||
@@ -61,11 +61,6 @@
|
|||||||
} else {
|
} else {
|
||||||
delete Date.now;
|
delete Date.now;
|
||||||
}
|
}
|
||||||
if (Function.prototype._bind) {
|
|
||||||
Function.prototype.bind = Function.prototype._bind;
|
|
||||||
} else {
|
|
||||||
delete Function.prototype.bind;
|
|
||||||
}
|
|
||||||
if (Object._create) {
|
if (Object._create) {
|
||||||
Object.create = Object._create;
|
Object.create = Object._create;
|
||||||
} else {
|
} else {
|
||||||
@@ -86,6 +81,11 @@
|
|||||||
} else {
|
} else {
|
||||||
delete Object.keys;
|
delete Object.keys;
|
||||||
}
|
}
|
||||||
|
if (String.prototype._contains) {
|
||||||
|
String.prototype.contains = String.prototype._contains;
|
||||||
|
} else {
|
||||||
|
delete String.prototype.contains;
|
||||||
|
}
|
||||||
window.WinRTError = undefined;
|
window.WinRTError = undefined;
|
||||||
|
|
||||||
document.createDocumentFragment = document._createDocumentFragment;
|
document.createDocumentFragment = document._createDocumentFragment;
|
||||||
@@ -93,12 +93,12 @@
|
|||||||
|
|
||||||
delete Array._isArray;
|
delete Array._isArray;
|
||||||
delete Date._now;
|
delete Date._now;
|
||||||
delete Function.prototype._bind;
|
|
||||||
delete Function.prototype._method;
|
delete Function.prototype._method;
|
||||||
delete Object._create;
|
delete Object._create;
|
||||||
delete Object._defineProperty;
|
delete Object._defineProperty;
|
||||||
delete Object._getPrototypeOf;
|
delete Object._getPrototypeOf;
|
||||||
delete Object._keys;
|
delete Object._keys;
|
||||||
|
delete String.prototype._contains;
|
||||||
}
|
}
|
||||||
|
|
||||||
addBizarroMethods();
|
addBizarroMethods();
|
||||||
|
|||||||
27
test/test.js
27
test/test.js
@@ -249,9 +249,6 @@
|
|||||||
var _now = Date.now;
|
var _now = Date.now;
|
||||||
Date.now = function() {};
|
Date.now = function() {};
|
||||||
|
|
||||||
var _bind = Function.prototype.bind;
|
|
||||||
Function.prototype.bind = function() { return function() {}; };
|
|
||||||
|
|
||||||
var _create = Object.create;
|
var _create = Object.create;
|
||||||
Object.create = function() {};
|
Object.create = function() {};
|
||||||
|
|
||||||
@@ -264,18 +261,25 @@
|
|||||||
var _keys = Object.keys;
|
var _keys = Object.keys;
|
||||||
Object.keys = function() {};
|
Object.keys = function() {};
|
||||||
|
|
||||||
|
var _contains = String.prototype.contains;
|
||||||
|
String.prototype.contains = function() {};
|
||||||
|
|
||||||
// load Lo-Dash and expose it to the bad extensions/shims
|
// load Lo-Dash and expose it to the bad extensions/shims
|
||||||
lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro;
|
lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro;
|
||||||
|
|
||||||
// restore native methods
|
// restore native methods
|
||||||
Array.isArray = _isArray;
|
Array.isArray = _isArray;
|
||||||
Date.now = _now;
|
Date.now = _now;
|
||||||
Function.prototype.bind = _bind;
|
|
||||||
Object.create = _create;
|
Object.create = _create;
|
||||||
Object.defineProperty = _defineProperty;
|
Object.defineProperty = _defineProperty;
|
||||||
Object.getPrototypeOf = _getPrototypeOf;
|
Object.getPrototypeOf = _getPrototypeOf;
|
||||||
Object.keys = _keys;
|
Object.keys = _keys;
|
||||||
|
|
||||||
|
if (String.prototype._contains) {
|
||||||
|
String.prototype.contains = String.prototype._contains;
|
||||||
|
} else {
|
||||||
|
delete String.prototype.contains;
|
||||||
|
}
|
||||||
delete global.window;
|
delete global.window;
|
||||||
delete global.WinRTError;
|
delete global.WinRTError;
|
||||||
delete Function.prototype._method;
|
delete Function.prototype._method;
|
||||||
@@ -384,7 +388,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should avoid overwritten native methods', 7, function() {
|
test('should avoid overwritten native methods', 8, function() {
|
||||||
function Foo() {}
|
function Foo() {}
|
||||||
|
|
||||||
function message(methodName) {
|
function message(methodName) {
|
||||||
@@ -416,11 +420,11 @@
|
|||||||
deepEqual(actual[1], {}, message('Object.create'));
|
deepEqual(actual[1], {}, message('Object.create'));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var actual = lodashBizarro.bind(function() { return this.a; }, object)();
|
var actual = lodashBizarro.bind(function() { return this.a; }, object);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
actual = null;
|
actual = null;
|
||||||
}
|
}
|
||||||
ok(actual, message('Object.defineProperty'));
|
equal('__bindData__' in actual, false, message('Object.defineProperty'));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
actual = [lodashBizarro.isPlainObject({}), lodashBizarro.isPlainObject([])];
|
actual = [lodashBizarro.isPlainObject({}), lodashBizarro.isPlainObject([])];
|
||||||
@@ -435,9 +439,16 @@
|
|||||||
actual = null;
|
actual = null;
|
||||||
}
|
}
|
||||||
deepEqual(actual, [['a'], []], message('Object.keys'));
|
deepEqual(actual, [['a'], []], message('Object.keys'));
|
||||||
|
|
||||||
|
try {
|
||||||
|
actual = lodashBizarro.contains('abc', 'bc');
|
||||||
|
} catch(e) {
|
||||||
|
actual = null;
|
||||||
|
}
|
||||||
|
strictEqual(actual, true, message('String#contains'));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(7);
|
skipTest(8);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|||||||
Reference in New Issue
Block a user