Skip to content

Commit 89d3980

Browse files
committed
feat: add tests
1 parent 008e127 commit 89d3980

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/tests/utils.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,40 @@ describe('makeSdObject function', () => {
7575
}
7676
})
7777
})
78+
79+
it('should camelCase values when setCasing is not given', () => {
80+
const obj: { [key: string]: string } = {
81+
'foo.foo-bar': 'bar',
82+
}
83+
84+
const result = {}
85+
Object.keys(obj).forEach((key) => {
86+
const keys = key.split('.').filter((k) => k !== 'colors')
87+
makeSdObject(result, keys, obj[key])
88+
})
89+
90+
expect(result).toEqual({
91+
foo: {
92+
fooBar: 'bar'
93+
}
94+
})
95+
})
96+
97+
it('should not camelCase when setCasing is set to false', () => {
98+
const obj: { [key: string]: string } = {
99+
'typography.foo-bar': 'bar',
100+
}
101+
102+
const result = {}
103+
Object.keys(obj).forEach((key) => {
104+
const keys = key.split('.').filter((k) => k !== 'colors')
105+
makeSdObject(result, keys, obj[key], false)
106+
})
107+
108+
expect(result).toEqual({
109+
typography: {
110+
'foo-bar': 'bar'
111+
}
112+
})
113+
})
78114
})

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const makeSdObject = <T extends readonly string[]>(
99
obj: SdObjType<{ [key: string]: any }>,
1010
keys: T,
1111
value: string,
12-
setCasing: boolean
12+
setCasing = true
1313
): void => {
1414
const lastIndex = keys.length - 1
1515
for (let i = 0; i < lastIndex; ++i) {

0 commit comments

Comments
 (0)