Skip to content

Commit

Permalink
[minor] Clean-up and additional tests for #173 #172
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Apr 12, 2019
1 parent d0f5c69 commit a871896
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
}

/**
Expand Down
24 changes: 24 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit a871896

Please sign in to comment.