mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Add tests for overwriting native Number.isFinite.
This commit is contained in:
@@ -99,6 +99,9 @@
|
|||||||
return wrapper;
|
return wrapper;
|
||||||
}()));
|
}()));
|
||||||
|
|
||||||
|
setProperty(Number, '_isFinite', Number.isFinite);
|
||||||
|
setProperty(Number, 'isFinite', function() {});
|
||||||
|
|
||||||
setProperty(String.prototype, '_contains', String.prototype.contains);
|
setProperty(String.prototype, '_contains', String.prototype.contains);
|
||||||
setProperty(String.prototype, 'contains', String.prototype._contains ? function() {} : Boolean);
|
setProperty(String.prototype, 'contains', String.prototype._contains ? function() {} : Boolean);
|
||||||
|
|
||||||
@@ -146,6 +149,11 @@
|
|||||||
} else {
|
} else {
|
||||||
delete Object.keys;
|
delete Object.keys;
|
||||||
}
|
}
|
||||||
|
if (Number._isFinite) {
|
||||||
|
setProperty(Number, 'isFinite', Number._isFinite);
|
||||||
|
} else {
|
||||||
|
delete Number.isFinite;
|
||||||
|
}
|
||||||
if (String.prototype._contains) {
|
if (String.prototype._contains) {
|
||||||
setProperty(String.prototype, 'contains', String.prototype._contains);
|
setProperty(String.prototype, 'contains', String.prototype._contains);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
20
test/test.js
20
test/test.js
@@ -379,6 +379,9 @@
|
|||||||
return _hasOwnProperty.call(this, key);
|
return _hasOwnProperty.call(this, key);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var _isFinite = Number.isFinite;
|
||||||
|
setProperty(Number, 'isFinite', _.noop);
|
||||||
|
|
||||||
var _contains = String.prototype.contains;
|
var _contains = String.prototype.contains;
|
||||||
setProperty(String.prototype, 'contains', _contains ? _.noop : Boolean);
|
setProperty(String.prototype, 'contains', _contains ? _.noop : Boolean);
|
||||||
|
|
||||||
@@ -399,9 +402,15 @@
|
|||||||
setProperty(Object, 'defineProperty', _defineProperty);
|
setProperty(Object, 'defineProperty', _defineProperty);
|
||||||
setProperty(Object, 'getPrototypeOf', _getPrototypeOf);
|
setProperty(Object, 'getPrototypeOf', _getPrototypeOf);
|
||||||
setProperty(Object, 'keys', _keys);
|
setProperty(Object, 'keys', _keys);
|
||||||
|
|
||||||
setProperty(Object.prototype, 'hasOwnProperty', _hasOwnProperty);
|
setProperty(Object.prototype, 'hasOwnProperty', _hasOwnProperty);
|
||||||
setProperty(Function.prototype, 'toString', _fnToString);
|
setProperty(Function.prototype, 'toString', _fnToString);
|
||||||
|
|
||||||
|
if (_isFinite) {
|
||||||
|
setProperty(Number, 'isFinite', _isFinite);
|
||||||
|
} else {
|
||||||
|
delete Number.isFinite;
|
||||||
|
}
|
||||||
if (_contains) {
|
if (_contains) {
|
||||||
setProperty(String.prototype, 'contains', _contains);
|
setProperty(String.prototype, 'contains', _contains);
|
||||||
} else {
|
} else {
|
||||||
@@ -524,7 +533,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should avoid overwritten native methods', 12, function() {
|
test('should avoid overwritten native methods', 13, function() {
|
||||||
function Foo() {}
|
function Foo() {}
|
||||||
|
|
||||||
function message(methodName) {
|
function message(methodName) {
|
||||||
@@ -579,6 +588,13 @@
|
|||||||
}
|
}
|
||||||
deepEqual(actual, [['a'], []], message('Object.keys'));
|
deepEqual(actual, [['a'], []], message('Object.keys'));
|
||||||
|
|
||||||
|
try {
|
||||||
|
actual = [lodashBizarro.isFinite(1), lodashBizarro.isFinite(NaN)];
|
||||||
|
} catch(e) {
|
||||||
|
actual = null;
|
||||||
|
}
|
||||||
|
deepEqual(actual, [true, false], message('Number.isFinite'));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
actual = [
|
actual = [
|
||||||
lodashBizarro.difference([object, otherObject], largeArray),
|
lodashBizarro.difference([object, otherObject], largeArray),
|
||||||
@@ -613,7 +629,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(12);
|
skipTest(13);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|||||||
Reference in New Issue
Block a user