Skip to content

Commit 3e146e8

Browse files
committed
chore: added tests for ldClient and boolean flag
1 parent 6e3caf7 commit 3e146e8

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
4+
5+
import { mockFlags, resetLDMocks } from '@launchdarkly/jest/react-native';
6+
import { screen, render } from '@testing-library/react-native';
7+
import { useLDClient } from '@launchdarkly/react-native-client-sdk';
8+
import Welcome from './welcome';
9+
10+
describe('Welcome component test', () => {
11+
12+
afterEach(() => {
13+
resetLDMocks();
14+
});
15+
16+
test('mock boolean flag correctly', () => {
17+
mockFlags({ 'my-boolean-flag': true });
18+
render(<Welcome />);
19+
expect(screen.getByText('Flag value is true')).toBeTruthy();
20+
});
21+
22+
test('mock ldClient correctly', () => {
23+
const current = useLDClient();
24+
25+
current?.track('event');
26+
expect(current.track).toHaveBeenCalledTimes(1);
27+
});
28+
29+
});

packages/tooling/jest/example/react-native-example/src/welcome.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { StyleSheet, Text, View } from 'react-native';
2-
import { useBoolVariation, useLDClient } from '@launchdarkly/react-native-client-sdk';
2+
import { useLDClient } from '@launchdarkly/react-native-client-sdk';
33

44
export default function Welcome() {
55

6-
//TODO Set my-boolean-flag to a valid boolean flag key in your project/environment.
7-
const flagValue = useBoolVariation('my-boolean-flag', false);
8-
96
const ldClient = useLDClient();
107

11-
ldClient.track('test event');
8+
const flagValue = ldClient.boolVariation('my-boolean-flag', false);
129

1310
return (
1411
<View style={styles.container}>

0 commit comments

Comments
 (0)