Skip to content

Commit a871896

Browse files
committedApr 12, 2019
[minor] Clean-up and additional tests for #173 #172
1 parent d0f5c69 commit a871896

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed
 

‎index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var required = require('requires-port')
1414
* @public
1515
*/
1616
function trimLeft(str) {
17-
return (str ? str.toString() : '').replace(left, '');
17+
return (str ? str : '').toString().replace(left, '');
1818
}
1919

2020
/**

‎test/test.js

+24
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,30 @@ describe('url-parse', function () {
4242
global = globalVar;
4343
});
4444

45+
describe('trimLeft', function () {
46+
it('is a function', function () {
47+
assume(parse.trimLeft).is.a('function');
48+
});
49+
50+
it('removes whitespace on the left', function () {
51+
assume(parse.trimLeft(' lol')).equals('lol');
52+
});
53+
54+
it('calls toString on a given value', function () {
55+
//
56+
// When users pass in `window.location` it's not an actual string
57+
// so you can't replace on it. So it needs to be cast to a string.
58+
//
59+
const fake = {
60+
toString() {
61+
return 'wat'
62+
}
63+
};
64+
65+
assume(parse.trimLeft(fake)).equals('wat');
66+
});
67+
});
68+
4569
describe('extractProtocol', function () {
4670
it('extracts the protocol data', function () {
4771
assume(parse.extractProtocol('http://example.com')).eql({

0 commit comments

Comments
 (0)
Please sign in to comment.