Fix lodashBizarro tests for trim, trimLeft, and trimRight.

This commit is contained in:
John-David Dalton
2014-01-03 11:05:09 -06:00
parent c07ef0d92a
commit 0b4029f7a1
2 changed files with 15 additions and 28 deletions

View File

@@ -45,13 +45,13 @@
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 = 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;
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;
String.prototype.trimRight = String.prototype._trimRight ? function() {} : Boolean; String.prototype.trimRight = String.prototype._trimRight ? function() {} : String;
window.WinRTError = Error; window.WinRTError = Error;

View File

@@ -268,13 +268,13 @@
String.prototype.contains = _contains ? function() {} : Boolean; String.prototype.contains = _contains ? function() {} : Boolean;
var _trim = String.prototype.trim; var _trim = String.prototype.trim;
String.prototype.trim = _trim ? function() {} : Boolean; String.prototype.trim = _trim ? function() {} : String;
var _trimLeft = String.prototype.trimLeft; var _trimLeft = String.prototype.trimLeft;
String.prototype.trimLeft = _trimLeft ? function() {} : Boolean; String.prototype.trimLeft = _trimLeft ? function() {} : String;
var _trimRight = String.prototype.trimRight; 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 // load Lo-Dash and expose it to the bad extensions/shims
lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro; lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro;
@@ -422,8 +422,7 @@
function message(methodName) { function message(methodName) {
return '`_.' + methodName + '` should avoid overwritten native methods'; return '`_.' + methodName + '` should avoid overwritten native methods';
} }
var object = { 'a': true }, var object = { 'a': true };
string = whitespace + 'a b c' + whitespace;
if (lodashBizarro) { if (lodashBizarro) {
try { try {
@@ -476,26 +475,14 @@
} }
strictEqual(actual, true, message('String#contains')); strictEqual(actual, true, message('String#contains'));
try { _.forEach(['trim', 'trimLeft', 'trimRight'], function(methodName) {
actual = lodashBizarro.trim(string); try {
} catch(e) { var actual = lodashBizarro[methodName](whitespace + 'a b c' + whitespace);
actual = null; } catch(e) {
} actual = null;
strictEqual(actual, 'a b c', message('String#trim')); }
equal(typeof actual, 'string', message('String#' + methodName));
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'));
} }
else { else {
skipTest(11); skipTest(11);