From 0b4029f7a1b7a87fef0fd381b705502aa5268928 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 3 Jan 2014 11:05:09 -0600 Subject: [PATCH] Fix lodashBizarro tests for trim, trimLeft, and trimRight. --- test/index.html | 6 +++--- test/test.js | 37 ++++++++++++------------------------- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/test/index.html b/test/index.html index 8dbfa4ead..cdd574c9b 100644 --- a/test/index.html +++ b/test/index.html @@ -45,13 +45,13 @@ String.prototype.contains = String.prototype._contains ? function() {} : Boolean; String.prototype._trim = String.prototype.trim; - String.prototype.trim = String.prototype._trim ? function() {} : Boolean; + String.prototype.trim = String.prototype._trim ? function() {} : String; String.prototype._trimLeft = String.prototype.trimLeft; - String.prototype.trimLeft = String.prototype._trimLeft ? function() {} : Boolean; + String.prototype.trimLeft = String.prototype._trimLeft ? function() {} : String; String.prototype._trimRight = String.prototype.trimRight; - String.prototype.trimRight = String.prototype._trimRight ? function() {} : Boolean; + String.prototype.trimRight = String.prototype._trimRight ? function() {} : String; window.WinRTError = Error; diff --git a/test/test.js b/test/test.js index eb16926ad..3321e9581 100644 --- a/test/test.js +++ b/test/test.js @@ -268,13 +268,13 @@ String.prototype.contains = _contains ? function() {} : Boolean; var _trim = String.prototype.trim; - String.prototype.trim = _trim ? function() {} : Boolean; + String.prototype.trim = _trim ? function() {} : String; var _trimLeft = String.prototype.trimLeft; - String.prototype.trimLeft = _trimLeft ? function() {} : Boolean; + String.prototype.trimLeft = _trimLeft ? function() {} : String; var _trimRight = String.prototype.trimRight; - String.prototype.trimRight = _trimRight ? function() {} : Boolean; + String.prototype.trimRight = _trimRight ? function() {} : String; // load Lo-Dash and expose it to the bad extensions/shims lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro; @@ -422,8 +422,7 @@ function message(methodName) { return '`_.' + methodName + '` should avoid overwritten native methods'; } - var object = { 'a': true }, - string = whitespace + 'a b c' + whitespace; + var object = { 'a': true }; if (lodashBizarro) { try { @@ -476,26 +475,14 @@ } strictEqual(actual, true, message('String#contains')); - try { - actual = lodashBizarro.trim(string); - } catch(e) { - actual = null; - } - strictEqual(actual, 'a b c', message('String#trim')); - - try { - actual = lodashBizarro.trimLeft(string); - } catch(e) { - actual = null; - } - strictEqual(actual, 'a b c' + whitespace, message('String#trimLeft')); - - try { - actual = lodashBizarro.trimRight(string); - } catch(e) { - actual = null; - } - strictEqual(actual, whitespace + 'a b c', message('String#trimRight')); + _.forEach(['trim', 'trimLeft', 'trimRight'], function(methodName) { + try { + var actual = lodashBizarro[methodName](whitespace + 'a b c' + whitespace); + } catch(e) { + actual = null; + } + equal(typeof actual, 'string', message('String#' + methodName)); + }); } else { skipTest(11);