Skip to content

Commit

Permalink
Fix removeLeft module and add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Murilo Camargos committed Feb 6, 2018
1 parent a1411d1 commit e499b2f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/removeleft.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import substr from './substr'
*/
export default (value: string, prefix: string, caseSensitive: boolean = true): string => {
if (startsWith(value, prefix, 0, caseSensitive)) {
return substr(value, prefix.length)
return substr(value, prefix.length, value.length - prefix.length)
}
return value
}
8 changes: 8 additions & 0 deletions test/removeleft.strman.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ describe('strman.removeLeft', () => {
expect(removeLeft(el, 'foo')).toBe('bar')
})
})

test('should be Foobar', () => {
expect(removeLeft('Foobar', 'foo')).toBe('Foobar')
})

test('should be bar', () => {
expect(removeLeft('Foobar', 'foo', false)).toBe('bar')
})
})
8 changes: 8 additions & 0 deletions test/removeleft.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ describe('strman.removeLeft', () => {
expect(removeLeft(el, 'foo')).toBe('bar')
})
})

test('should be Foobar', () => {
expect(removeLeft('Foobar', 'foo')).toBe('Foobar')
})

test('should be bar', () => {
expect(removeLeft('Foobar', 'foo', false)).toBe('bar')
})
})

0 comments on commit e499b2f

Please sign in to comment.