File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ var required = require('requires-port')
1414 * @public
1515 */
1616function trimLeft ( str ) {
17- return ( str ? str . toString ( ) : '' ) . replace ( left , '' ) ;
17+ return ( str ? str : '' ) . toString ( ) . replace ( left , '' ) ;
1818}
1919
2020/**
Original file line number Diff line number Diff 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 ( {
You can’t perform that action at this time.
0 commit comments