Skip to content

Commit c26ee61

Browse files
committed
chore: adding camelcase flag keys to useFlags hook
1 parent aba6b0c commit c26ee61

10 files changed

Lines changed: 435 additions & 99 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { toCamelCase } from '../../../src/client/deprecated-hooks/flagKeyUtils';
2+
3+
it('converts kebab-case to camelCase', () => {
4+
expect(toCamelCase('my-flag-key')).toBe('myFlagKey');
5+
});
6+
7+
it('converts snake_case to camelCase', () => {
8+
expect(toCamelCase('my_flag_key')).toBe('myFlagKey');
9+
});
10+
11+
it('converts dot.separated to camelCase', () => {
12+
expect(toCamelCase('my.flag.key')).toBe('myFlagKey');
13+
});
14+
15+
it('lowercases ALL_CAPS first word', () => {
16+
expect(toCamelCase('MY_FLAG')).toBe('myFlag');
17+
});
18+
19+
it('preserves already-camelCase keys', () => {
20+
expect(toCamelCase('myFlagKey')).toBe('myFlagKey');
21+
});
22+
23+
it('handles HTMLParser (ALLCAPS boundary)', () => {
24+
expect(toCamelCase('HTMLParser')).toBe('htmlParser');
25+
});
26+
27+
it('handles a single word with no separators', () => {
28+
expect(toCamelCase('flag')).toBe('flag');
29+
});
30+
31+
it('handles runs of multiple separators', () => {
32+
expect(toCamelCase('my--flag')).toBe('myFlag');
33+
expect(toCamelCase('my_.flag')).toBe('myFlag');
34+
});
35+
36+
it('handles empty string', () => {
37+
expect(toCamelCase('')).toBe('');
38+
});

packages/sdk/react/__tests__/client/deprecated-hooks/renderHelpers.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import { LDReactClientContextValue } from '../../../src/client/LDClient';
44
import { LDReactContext } from '../../../src/client/provider/LDReactContext';
55
import { makeMockClient } from '../mockClient';
66

7-
export function makeWrapper(mockClient: ReturnType<typeof makeMockClient>) {
7+
export function makeWrapper(
8+
mockClient: ReturnType<typeof makeMockClient>,
9+
contextOverrides?: Partial<LDReactClientContextValue>,
10+
) {
811
const contextValue: LDReactClientContextValue = {
912
client: mockClient,
1013
initializedState: 'unknown',
14+
...contextOverrides,
1115
};
1216

1317
return function Wrapper({ children }: { children: React.ReactNode }) {

0 commit comments

Comments
 (0)