Skip to content

Instantly share code, notes, and snippets.

@codexico
Created February 28, 2019 23:27
Show Gist options
  • Save codexico/197362810b4c8a00be8cc519abd579fc to your computer and use it in GitHub Desktop.
Save codexico/197362810b4c8a00be8cc519abd579fc to your computer and use it in GitHub Desktop.
function to capitalize text
// 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