File tree Expand file tree Collapse file tree 2 files changed +31
-5
lines changed
packages/tooling/jest/example/react-native-example/src Expand file tree Collapse file tree 2 files changed +31
-5
lines changed Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 11import { 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
44export 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 } >
You can’t perform that action at this time.
0 commit comments