File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 33// Problem Source & Explanation: https://en.wikipedia.org/wiki/Naming_convention_(programming)
44
55/**
6- * CheckSnakeCase method returns true if the string in snake_case, else return the false.
6+ * checkSnakeCase method returns true if the string in snake_case, else return the false.
77 * @param {String } varName the name of the variable to check.
88 * @returns `Boolean` return true if the string is in snake_case, else return false.
99 */
10- const CheckSnakeCase = ( varName ) => {
10+ const checkSnakeCase = ( varName ) => {
1111 // firstly, check that input is a string or not.
1212 if ( typeof varName !== 'string' ) {
13- return new TypeError ( 'Argument is not a string.' )
13+ throw new TypeError ( 'Argument is not a string.' )
1414 }
1515
1616 const pat = / ( .* ?) _ ( [ a - z A - Z ] ) * /
1717 return pat . test ( varName )
1818}
1919
20- module . exports = CheckSnakeCase
20+ export { checkSnakeCase }
Original file line number Diff line number Diff line change 1+ import { checkSnakeCase } from '../CheckSnakeCase'
2+ describe ( 'checkSnakeCase' , ( ) => {
3+ it ( 'expect to throw an error if input is not a string' , ( ) => {
4+ expect ( ( ) => checkSnakeCase ( 0 ) ) . toThrow ( )
5+ } )
6+
7+ it ( 'expects to return true if the input is in snake case format' , ( ) => {
8+ const value = 'docker_build'
9+ const result = checkSnakeCase ( value )
10+ expect ( result ) . toBe ( true )
11+ } )
12+
13+ it ( 'expects to return false if the input is not in snake case format' , ( ) => {
14+ const value = 'dockerBuild'
15+ const result = checkSnakeCase ( value )
16+ expect ( result ) . toBe ( false )
17+ } )
18+ } )
You can’t perform that action at this time.
0 commit comments