diff --git a/index.js b/index.js index 5ed9e32..9e58eda 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ var required = require('requires-port') * @public */ function trimLeft(str) { - return (str ? str.toString() : '').replace(left, ''); + return (str ? str : '').toString().replace(left, ''); } /** diff --git a/test/test.js b/test/test.js index 9218fe4..b1e196c 100644 --- a/test/test.js +++ b/test/test.js @@ -42,6 +42,30 @@ describe('url-parse', function () { global = globalVar; }); + describe('trimLeft', function () { + it('is a function', function () { + assume(parse.trimLeft).is.a('function'); + }); + + it('removes whitespace on the left', function () { + assume(parse.trimLeft(' lol')).equals('lol'); + }); + + it('calls toString on a given value', function () { + // + // When users pass in `window.location` it's not an actual string + // so you can't replace on it. So it needs to be cast to a string. + // + const fake = { + toString() { + return 'wat' + } + }; + + assume(parse.trimLeft(fake)).equals('wat'); + }); + }); + describe('extractProtocol', function () { it('extracts the protocol data', function () { assume(parse.extractProtocol('http://example.com')).eql({