mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Ensure the trim fallback is tested and counted for code coverage.
This commit is contained in:
@@ -44,6 +44,9 @@
|
|||||||
String.prototype._contains = String.prototype.contains;
|
String.prototype._contains = String.prototype.contains;
|
||||||
String.prototype.contains = String.prototype._contains ? function() {} : Boolean;
|
String.prototype.contains = String.prototype._contains ? function() {} : Boolean;
|
||||||
|
|
||||||
|
String.prototype._trim = String.prototype.trim;
|
||||||
|
String.prototype.trim = function() {};
|
||||||
|
|
||||||
window.WinRTError = Error;
|
window.WinRTError = Error;
|
||||||
|
|
||||||
document._createDocumentFragment = document.createDocumentFragment;
|
document._createDocumentFragment = document.createDocumentFragment;
|
||||||
@@ -86,6 +89,20 @@
|
|||||||
} else {
|
} else {
|
||||||
delete String.prototype.contains;
|
delete String.prototype.contains;
|
||||||
}
|
}
|
||||||
|
if (String.prototype._trim) {
|
||||||
|
if (Object.defineProperty) {
|
||||||
|
Object.defineProperty(String.prototype, 'trim', {
|
||||||
|
'configurable': true,
|
||||||
|
'enumerable': false,
|
||||||
|
'writable': true,
|
||||||
|
'value': String.prototype._trim
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
String.prototype.trim = String.prototype._trim;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
delete String.prototype.trim;
|
||||||
|
}
|
||||||
window.WinRTError = undefined;
|
window.WinRTError = undefined;
|
||||||
|
|
||||||
document.createDocumentFragment = document._createDocumentFragment;
|
document.createDocumentFragment = document._createDocumentFragment;
|
||||||
@@ -99,6 +116,7 @@
|
|||||||
delete Object._getPrototypeOf;
|
delete Object._getPrototypeOf;
|
||||||
delete Object._keys;
|
delete Object._keys;
|
||||||
delete String.prototype._contains;
|
delete String.prototype._contains;
|
||||||
|
delete String.prototype._trim;
|
||||||
}
|
}
|
||||||
|
|
||||||
addBizarroMethods();
|
addBizarroMethods();
|
||||||
|
|||||||
26
test/test.js
26
test/test.js
@@ -264,6 +264,9 @@
|
|||||||
var _contains = String.prototype.contains;
|
var _contains = String.prototype.contains;
|
||||||
String.prototype.contains = _contains ? function() {} : Boolean;
|
String.prototype.contains = _contains ? function() {} : Boolean;
|
||||||
|
|
||||||
|
var _trim = String.prototype.trim;
|
||||||
|
String.prototype.trim = _trim ? function() {} : Boolean;
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
||||||
@@ -280,6 +283,18 @@
|
|||||||
} else {
|
} else {
|
||||||
delete String.prototype.contains;
|
delete String.prototype.contains;
|
||||||
}
|
}
|
||||||
|
if (_trim) {
|
||||||
|
// avoid a bug where overwriting non-enumerable built-ins makes them enumerable
|
||||||
|
// https://code.google.com/p/v8/issues/detail?id=1623
|
||||||
|
defineProperty(String.prototype, 'trim', {
|
||||||
|
'configurable': true,
|
||||||
|
'enumerable': false,
|
||||||
|
'writable': true,
|
||||||
|
'value': _trim
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
delete String.prototype.trim;
|
||||||
|
}
|
||||||
delete global.window;
|
delete global.window;
|
||||||
delete global.WinRTError;
|
delete global.WinRTError;
|
||||||
delete Function.prototype._method;
|
delete Function.prototype._method;
|
||||||
@@ -388,7 +403,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should avoid overwritten native methods', 8, function() {
|
test('should avoid overwritten native methods', 9, function() {
|
||||||
function Foo() {}
|
function Foo() {}
|
||||||
|
|
||||||
function message(methodName) {
|
function message(methodName) {
|
||||||
@@ -446,9 +461,16 @@
|
|||||||
actual = null;
|
actual = null;
|
||||||
}
|
}
|
||||||
strictEqual(actual, true, message('String#contains'));
|
strictEqual(actual, true, message('String#contains'));
|
||||||
|
|
||||||
|
try {
|
||||||
|
actual = lodashBizarro.parseInt(' 08 ');
|
||||||
|
} catch(e) {
|
||||||
|
actual = null;
|
||||||
|
}
|
||||||
|
strictEqual(actual, 8, message('String#trim'));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(8);
|
skipTest(9);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|||||||
Reference in New Issue
Block a user