From d504b1f90fd228707330cb887deb3220f75366c8 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 16 Jul 2014 00:12:08 -0700 Subject: [PATCH] Add tests for overwriting native `Number.isFinite`. --- test/index.html | 8 ++++++++ test/test.js | 20 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/test/index.html b/test/index.html index 6383260ad..94101934f 100644 --- a/test/index.html +++ b/test/index.html @@ -99,6 +99,9 @@ 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 ? function() {} : Boolean); @@ -146,6 +149,11 @@ } else { delete Object.keys; } + if (Number._isFinite) { + setProperty(Number, 'isFinite', Number._isFinite); + } else { + delete Number.isFinite; + } if (String.prototype._contains) { setProperty(String.prototype, 'contains', String.prototype._contains); } else { diff --git a/test/test.js b/test/test.js index 0c1502f03..b2322b058 100644 --- a/test/test.js +++ b/test/test.js @@ -379,6 +379,9 @@ return _hasOwnProperty.call(this, key); }); + var _isFinite = Number.isFinite; + setProperty(Number, 'isFinite', _.noop); + var _contains = String.prototype.contains; setProperty(String.prototype, 'contains', _contains ? _.noop : Boolean); @@ -399,9 +402,15 @@ setProperty(Object, 'defineProperty', _defineProperty); setProperty(Object, 'getPrototypeOf', _getPrototypeOf); setProperty(Object, 'keys', _keys); + setProperty(Object.prototype, 'hasOwnProperty', _hasOwnProperty); setProperty(Function.prototype, 'toString', _fnToString); + if (_isFinite) { + setProperty(Number, 'isFinite', _isFinite); + } else { + delete Number.isFinite; + } if (_contains) { setProperty(String.prototype, 'contains', _contains); } else { @@ -524,7 +533,7 @@ } }); - test('should avoid overwritten native methods', 12, function() { + test('should avoid overwritten native methods', 13, function() { function Foo() {} function message(methodName) { @@ -579,6 +588,13 @@ } 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 { actual = [ lodashBizarro.difference([object, otherObject], largeArray), @@ -613,7 +629,7 @@ } } else { - skipTest(12); + skipTest(13); } }); }());