Created
February 28, 2019 23:27
-
-
Save codexico/197362810b4c8a00be8cc519abd579fc to your computer and use it in GitHub Desktop.
function to capitalize text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// string.js | |
export const capitalize = (string = '') => | |
(typeof string === 'string' && string.substring(1)) | |
? string[0].toUpperCase() + string.substring(1).toLowerCase() | |
: ''; | |
// string.test.js | |
import { capitalize } from './string'; | |
describe('[Helpers] string', () => { | |
describe('capitalize()', () => { | |
it('should return string Capitalized', () => { | |
expect(capitalize()).toEqual(''); | |
expect(capitalize('')).toEqual(''); | |
expect(capitalize('foo')).toEqual('Foo'); | |
expect(capitalize('fOO')).toEqual('Foo'); | |
expect(capitalize(0)).toEqual(''); | |
expect(capitalize(1)).toEqual(''); | |
expect(capitalize(true)).toEqual(''); | |
expect(capitalize(false)).toEqual(''); | |
expect(capitalize('foo bar')).toEqual('Foo bar'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment