File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ import { toCamelCase , toSnakeCase } from './utils' ;
2+
3+ describe ( 'utils' , ( ) => {
4+ describe ( 'toCamelCase' , ( ) => {
5+ it ( 'should convert snake_case to camelCase' , ( ) => {
6+ const obj = {
7+ foo_bar : 'foo' ,
8+ bar_baz : 'bar' ,
9+ } ;
10+ const expected = {
11+ fooBar : 'foo' ,
12+ barBaz : 'bar' ,
13+ } ;
14+ expect ( toCamelCase ( obj ) ) . toEqual ( expected ) ;
15+ } ) ;
16+
17+ it ( 'should convert to camelCase only snake_case keys' , ( ) => {
18+ const obj = {
19+ foo_bar : 'foo' ,
20+ bar_baz : 'bar' ,
21+ fooBar : 'foo' ,
22+ barBaz : 'bar' ,
23+ } ;
24+ const expected = {
25+ fooBar : 'foo' ,
26+ barBaz : 'bar' ,
27+ } ;
28+ expect ( toCamelCase ( obj ) ) . toEqual ( expected ) ;
29+ } ) ;
30+ } ) ;
31+
32+ describe ( 'toSnakeCase' , ( ) => {
33+ it ( 'should convert camelCase to snake_case' , ( ) => {
34+ const obj = {
35+ fooBar : 'foo' ,
36+ barBaz : 'bar' ,
37+ } ;
38+ const expected = {
39+ foo_bar : 'foo' ,
40+ bar_baz : 'bar' ,
41+ } ;
42+ expect ( toSnakeCase ( obj ) ) . toEqual ( expected ) ;
43+ } ) ;
44+
45+ it ( 'should convert to snake_case only camelCase keys' , ( ) => {
46+ const obj = {
47+ fooBar : 'foo' ,
48+ barBaz : 'bar' ,
49+ foo_bar : 'foo' ,
50+ bar_baz : 'bar' ,
51+ } ;
52+ const expected = {
53+ foo_bar : 'foo' ,
54+ bar_baz : 'bar' ,
55+ } ;
56+ expect ( toSnakeCase ( obj ) ) . toEqual ( expected ) ;
57+ } ) ;
58+ } ) ;
59+ } ) ;
You can’t perform that action at this time.
0 commit comments