1
1
jest . mock ( './initLDClient' , ( ) => jest . fn ( ) ) ;
2
2
jest . mock ( './context' , ( ) => ( { Provider : 'Provider' } ) ) ;
3
3
4
- import * as React from 'react' ;
4
+ import React , { Component } from 'react' ;
5
5
import { create } from 'react-test-renderer' ;
6
- import { shallow } from 'enzyme' ;
7
6
import { LDClient , LDFlagChangeset , LDFlagSet , LDOptions , LDUser } from 'launchdarkly-js-client-sdk' ;
8
7
import initLDClient from './initLDClient' ;
9
8
import { LDReactOptions , EnhancedComponent , defaultReactOptions , ProviderConfig } from './types' ;
@@ -80,7 +79,7 @@ describe('LDProvider', () => {
80
79
const user1 : LDUser = { key : 'yus' , name : 'yus ng' } ;
81
80
const user2 : LDUser = { key : 'launch' , name : 'darkly' } ;
82
81
const options : LDOptions = { bootstrap : { } } ;
83
- const ldClient : Promise < LDClient > = new Promise ( async resolve => {
82
+ const ldClient : Promise < LDClient > = new Promise ( async ( resolve ) => {
84
83
resolve ( ( await initLDClient ( clientSideID , user1 , defaultReactOptions , options , undefined ) ) . ldClient ) ;
85
84
86
85
return ;
@@ -101,7 +100,7 @@ describe('LDProvider', () => {
101
100
test ( 'ld client is created if passed in promise resolves as undefined' , async ( ) => {
102
101
const user : LDUser = { key : 'yus' , name : 'yus ng' } ;
103
102
const options : LDOptions = { bootstrap : { } } ;
104
- const ldClient : Promise < undefined > = new Promise ( async resolve => {
103
+ const ldClient : Promise < undefined > = new Promise ( async ( resolve ) => {
105
104
resolve ( undefined ) ;
106
105
107
106
return ;
@@ -129,8 +128,8 @@ describe('LDProvider', () => {
129
128
< App />
130
129
</ LDProvider >
131
130
) ;
132
- const component = shallow ( LaunchDarklyApp , { disableLifecycleMethods : true } ) ;
133
- const initialState = component . state ( ) as HocState ;
131
+ const component = create ( LaunchDarklyApp ) . toTree ( ) ?. instance as Component ;
132
+ const initialState = component . state as HocState ;
134
133
135
134
expect ( initialState . flags ) . toEqual ( { } ) ;
136
135
} ) ;
@@ -154,8 +153,8 @@ describe('LDProvider', () => {
154
153
< App />
155
154
</ LDProvider >
156
155
) ;
157
- const component = shallow ( LaunchDarklyApp , { disableLifecycleMethods : true } ) ;
158
- const initialState = component . state ( ) as HocState ;
156
+ const component = create ( LaunchDarklyApp ) . toTree ( ) ?. instance as Component ;
157
+ const initialState = component . state as HocState ;
159
158
160
159
expect ( mockInitLDClient ) . not . toHaveBeenCalled ( ) ;
161
160
expect ( initialState . flags ) . toEqual ( { testFlag : true , anotherTestFlag : false } ) ;
@@ -178,8 +177,8 @@ describe('LDProvider', () => {
178
177
< App />
179
178
</ LDProvider >
180
179
) ;
181
- const component = shallow ( LaunchDarklyApp , { disableLifecycleMethods : true } ) ;
182
- const initialState = component . state ( ) as HocState ;
180
+ const component = create ( LaunchDarklyApp ) . toTree ( ) ?. instance as Component ;
181
+ const initialState = component . state as HocState ;
183
182
184
183
expect ( mockInitLDClient ) . not . toHaveBeenCalled ( ) ;
185
184
expect ( initialState . flags ) . toEqual ( { 'test-flag' : true , 'another-test-flag' : false } ) ;
@@ -200,8 +199,8 @@ describe('LDProvider', () => {
200
199
< App />
201
200
</ LDProvider >
202
201
) ;
203
- const component = shallow ( LaunchDarklyApp , { disableLifecycleMethods : true } ) ;
204
- const initialState = component . state ( ) as HocState ;
202
+ const component = create ( LaunchDarklyApp ) . toTree ( ) ?. instance as Component ;
203
+ const initialState = component . state as HocState ;
205
204
206
205
expect ( mockInitLDClient ) . not . toHaveBeenCalled ( ) ;
207
206
expect ( initialState . flags ) . toEqual ( { testFlag : true , anotherTestFlag : false } ) ;
@@ -221,8 +220,8 @@ describe('LDProvider', () => {
221
220
< App />
222
221
</ LDProvider >
223
222
) ;
224
- const component = shallow ( LaunchDarklyApp , { disableLifecycleMethods : true } ) ;
225
- const initialState = component . state ( ) as HocState ;
223
+ const component = create ( LaunchDarklyApp ) . toTree ( ) ?. instance as Component ;
224
+ const initialState = component . state as HocState ;
226
225
227
226
expect ( mockInitLDClient ) . not . toHaveBeenCalled ( ) ;
228
227
expect ( initialState . flags ) . toEqual ( { testFlag : true , anotherTestFlag : false } ) ;
@@ -239,8 +238,8 @@ describe('LDProvider', () => {
239
238
< App />
240
239
</ LDProvider >
241
240
) ;
242
- const component = shallow ( LaunchDarklyApp , { disableLifecycleMethods : true } ) ;
243
- const initialState = component . state ( ) as HocState ;
241
+ const component = create ( LaunchDarklyApp ) . toTree ( ) ?. instance as Component ;
242
+ const initialState = component . state as HocState ;
244
243
245
244
expect ( mockInitLDClient ) . not . toHaveBeenCalled ( ) ;
246
245
expect ( initialState . flags ) . toEqual ( { } ) ;
0 commit comments