@vendasta/store
Version:
Components and data for Store
50 lines (49 loc) • 2.71 kB
JavaScript
import { CaseTransform } from './case-transform';
describe('CaseTransform', function () {
describe('snakeToCamelCase', function () {
it('should return null for null', function () {
expect(CaseTransform.snakeToCamelCase(null)).toBe(null);
});
it('should return an empty string for an empty string', function () {
expect(CaseTransform.snakeToCamelCase('')).toBe('');
});
it('should return the one-word string for a one-word string', function () {
expect(CaseTransform.snakeToCamelCase('abc')).toBe('abc');
});
it('should return the string for a one word string not starting with a letter', function () {
expect(CaseTransform.snakeToCamelCase('1abc')).toBe('1abc');
});
it('should return the camel case string for a snake case string', function () {
expect(CaseTransform.snakeToCamelCase('abc_def')).toBe('abcDef');
});
it('should return the string in camel case', function () {
expect(CaseTransform.snakeToCamelCase('1abc_def_foo_bar_hello_world2')).toBe('1abcDefFooBarHelloWorld2');
});
it('should return the camel case string for a long snake case string', function () {
expect(CaseTransform.snakeToCamelCase('abc_def_foo_bar_hello_world')).toBe('abcDefFooBarHelloWorld');
});
it('should return the camel case string for a snake case string starting with an underline', function () {
expect(CaseTransform.snakeToCamelCase('_i_am_a_little_1_pot_5400_')).toBe('iAmALittle1Pot5400');
});
});
describe('lowerToTitleCase', function () {
it('should return null for null', function () {
expect(CaseTransform.lowerToTitleCase(null)).toBe(null);
});
it('should return an empty string for an empty string', function () {
expect(CaseTransform.lowerToTitleCase(null)).toBe(null);
});
it('should capitalize the first letter for a one-word string', function () {
expect(CaseTransform.lowerToTitleCase('word')).toBe('Word');
});
it('should return the string for a capitalized string', function () {
expect(CaseTransform.lowerToTitleCase('SEO')).toBe('SEO');
});
it('should capitalized first letters of words in a multi-word string', function () {
expect(CaseTransform.lowerToTitleCase('i saw iron man')).toBe('I Saw Iron Man');
});
it('should not capitalize first letter of predefined words', function () {
expect(CaseTransform.lowerToTitleCase('content and experience')).toBe('Content and Experience');
});
});
});