Skip to content

Instantly share code, notes, and snippets.

@danielkellyio
Last active July 2, 2021 02:34
Show Gist options
  • Select an option

  • Save danielkellyio/08d4e5f0883d357fcd76e92f6f50819b to your computer and use it in GitHub Desktop.

Select an option

Save danielkellyio/08d4e5f0883d357fcd76e92f6f50819b to your computer and use it in GitHub Desktop.
String Test Example
import {ucFirst, snakeCase, camelCase, sentenceCase, ucWords, titleCase, nestedFromDot} from '~/helper/string'
describe('string helper functions', ()=>{
test('ucFirst capitalizes the first letter in a string', ()=>{
expect(ucFirst('hello world')).toBe('Hello world')
})
test('ucWords capitalizes the first letter in each word of a string', ()=>{
expect(ucWords('hello world')).toBe('Hello World')
})
// snake case
test('snake case converts dashed strings to snakecase', ()=>{
expect(snakeCase('hello-world')).toBe('hello_world')
})
test('snake case converts camel case strings to snakecase', ()=>{
expect(snakeCase('helloWorld')).toBe('hello_world')
})
test('snake case converts sentence case strings to snakecase', ()=>{
expect(snakeCase('Hello world')).toBe('hello_world')
})
//camel case
test('camel case converts dashed strings to camelcase', ()=>{
expect(camelCase('hello-world')).toBe('helloWorld')
})
test('camel case converts snake case strings to camelcase', ()=>{
expect(camelCase('hello_world')).toBe('helloWorld')
})
test('camel case converts sentence case strings to camelcase', ()=>{
expect(camelCase('Hello world')).toBe('helloWorld')
})
//sentence case
test('sentence case converts dashed strings to sentence case', ()=>{
expect(sentenceCase('hello-world')).toBe('Hello world')
})
test('sentence case converts snake case strings to sentence case', ()=>{
expect(sentenceCase('hello_world')).toBe('Hello world')
})
test('sentence case converts camelCase strings to sentence case', ()=>{
expect(sentenceCase('helloWorld')).toBe('Hello world')
})
//title case
test('title case converts dashed strings to title case', ()=>{
expect(titleCase('hello-world')).toBe('Hello World')
})
test('title case converts snake case strings to title case', ()=>{
expect(titleCase('hello_world')).toBe('Hello World')
})
test('title case converts camelCase strings to title case', ()=>{
expect(titleCase('helloWorld')).toBe('Hello World')
})
test('title case ignores filler words in the middle of the string', ()=>{
expect(titleCase('this is a test')).toBe('This is a Test')
})
test('title case capitalizes filler words at the beginning of the string', ()=>{
expect(titleCase('The test has begun')).toBe('The Test has Begun')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment