1919import * as React from 'react' ;
2020import { act } from 'react-dom/test-utils' ;
2121import { render , renderHook , screen , waitFor } from '@testing-library/react' ;
22- import '@testing-library/jest-dom/extend-expect ' ;
22+ import '@testing-library/jest-dom' ;
2323
2424import { OptimizelyProvider } from './Provider' ;
2525import { OnReadyResult , ReactSDKClient , VariableValuesObject } from './client' ;
@@ -71,6 +71,7 @@ describe('hooks', () => {
7171 let notificationListenerCallbacks : Array < ( ) => void > ;
7272 let optimizelyMock : ReactSDKClient ;
7373 let readySuccess : boolean ;
74+ // let reason: NotReadyReason;
7475 let userUpdateCallbacks : Array < ( ) => void > ;
7576 let UseExperimentLoggingComponent : React . FunctionComponent < any > ;
7677 let UseFeatureLoggingComponent : React . FunctionComponent < any > ;
@@ -84,15 +85,15 @@ describe('hooks', () => {
8485
8586 beforeEach ( ( ) => {
8687 getOnReadyPromise = ( { timeout = 0 } : any ) : Promise < OnReadyResult > =>
87- new Promise ( resolve => {
88- setTimeout ( function ( ) {
88+ new Promise ( ( resolve ) => {
89+ setTimeout ( function ( ) {
8990 resolve (
9091 Object . assign (
9192 {
9293 success : readySuccess ,
9394 } ,
9495 ! readySuccess && {
95- dataReadyPromise : new Promise ( r => setTimeout ( r , mockDelay ) ) ,
96+ dataReadyPromise : new Promise ( ( r ) => setTimeout ( r , mockDelay ) ) ,
9697 }
9798 )
9899 ) ;
@@ -109,21 +110,21 @@ describe('hooks', () => {
109110 decideMock = jest . fn ( ) ;
110111 setForcedDecisionMock = jest . fn ( ) ;
111112 hooksLoggerErrorSpy = jest . spyOn ( hooksLogger , 'error' ) ;
112- optimizelyMock = ( {
113+ optimizelyMock = {
113114 activate : activateMock ,
114- onReady : jest . fn ( ) . mockImplementation ( config => getOnReadyPromise ( config || { } ) ) ,
115+ onReady : jest . fn ( ) . mockImplementation ( ( config ) => getOnReadyPromise ( config || { } ) ) ,
115116 getFeatureVariables : jest . fn ( ) . mockImplementation ( ( ) => featureVariables ) ,
116117 isFeatureEnabled : isFeatureEnabledMock ,
117118 getVuid : jest . fn ( ) . mockReturnValue ( 'vuid_95bf72cebc774dfd8e8e580a5a1' ) ,
118- onUserUpdate : jest . fn ( ) . mockImplementation ( handler => {
119+ onUserUpdate : jest . fn ( ) . mockImplementation ( ( handler ) => {
119120 userUpdateCallbacks . push ( handler ) ;
120121 return ( ) => { } ;
121122 } ) ,
122123 notificationCenter : {
123124 addNotificationListener : jest . fn ( ) . mockImplementation ( ( type , handler ) => {
124125 notificationListenerCallbacks . push ( handler ) ;
125126 } ) ,
126- removeNotificationListener : jest . fn ( ) . mockImplementation ( id => { } ) ,
127+ removeNotificationListener : jest . fn ( ) . mockImplementation ( ( id ) => { } ) ,
127128 } ,
128129 user : {
129130 id : 'testuser' ,
@@ -132,15 +133,16 @@ describe('hooks', () => {
132133 isReady : ( ) => readySuccess ,
133134 getIsReadyPromiseFulfilled : ( ) => true ,
134135 getIsUsingSdkKey : ( ) => true ,
135- onForcedVariationsUpdate : jest . fn ( ) . mockImplementation ( handler => {
136+ onForcedVariationsUpdate : jest . fn ( ) . mockImplementation ( ( handler ) => {
136137 forcedVariationUpdateCallbacks . push ( handler ) ;
137138 return ( ) => { } ;
138139 } ) ,
139140 getForcedVariations : jest . fn ( ) . mockReturnValue ( { } ) ,
140141 decide : decideMock ,
141142 setForcedDecision : setForcedDecisionMock ,
142143 track : jest . fn ( ) ,
143- } as unknown ) as ReactSDKClient ;
144+ setUser : jest . fn ( ) ,
145+ } as unknown as ReactSDKClient ;
144146
145147 mockLog = jest . fn ( ) ;
146148 UseExperimentLoggingComponent = ( { options = { } , overrides = { } } : any ) => {
@@ -164,8 +166,8 @@ describe('hooks', () => {
164166
165167 afterEach ( async ( ) => {
166168 await optimizelyMock . onReady ( ) . then (
167- res => res . dataReadyPromise ,
168- err => null
169+ ( res ) => res . dataReadyPromise ,
170+ ( err ) => null
169171 ) ;
170172 hooksLoggerErrorSpy . mockReset ( ) ;
171173 } ) ;
@@ -204,16 +206,14 @@ describe('hooks', () => {
204206 < MyExperimentComponent options = { { timeout : mockDelay } } />
205207 </ OptimizelyProvider >
206208 ) ;
209+
207210 await waitFor ( ( ) => expect ( screen . getByTestId ( 'result' ) ) . toHaveTextContent ( 'null|false|false' ) ) ; // initial render
208211
209- await optimizelyMock . onReady ( ) ;
210212 await waitFor ( ( ) => expect ( screen . getByTestId ( 'result' ) ) . toHaveTextContent ( 'null|false|true' ) ) ; // when didTimeout
211213
212214 // Simulate datafile fetch completing after timeout has already passed
213215 // Activate now returns a variation
214216 activateMock . mockReturnValue ( '12345' ) ;
215- // Wait for completion of dataReadyPromise
216- await optimizelyMock . onReady ( ) . then ( res => res . dataReadyPromise ) ;
217217 await waitFor ( ( ) => expect ( screen . getByTestId ( 'result' ) ) . toHaveTextContent ( '12345|true|true' ) ) ; // when clientReady
218218 } ) ;
219219
@@ -255,7 +255,7 @@ describe('hooks', () => {
255255 activateMock . mockReturnValue ( '12345' ) ;
256256 // Simulate the user object changing
257257 await act ( async ( ) => {
258- userUpdateCallbacks . forEach ( fn => fn ( ) ) ;
258+ userUpdateCallbacks . forEach ( ( fn ) => fn ( ) ) ;
259259 } ) ;
260260 // component.update();
261261 // await waitFor(() => expect(screen.getByTestId('result')).toHaveTextContent('12345|true|false');
@@ -278,7 +278,7 @@ describe('hooks', () => {
278278 activateMock . mockReturnValue ( '12345' ) ;
279279 // Simulate the user object changing
280280 await act ( async ( ) => {
281- userUpdateCallbacks . forEach ( fn => fn ( ) ) ;
281+ userUpdateCallbacks . forEach ( ( fn ) => fn ( ) ) ;
282282 } ) ;
283283 await waitFor ( ( ) => expect ( screen . getByTestId ( 'result' ) ) . toHaveTextContent ( 'null|true|false' ) ) ;
284284 } ) ;
@@ -299,7 +299,7 @@ describe('hooks', () => {
299299 it ( 'should re-render after the client becomes ready' , async ( ) => {
300300 readySuccess = false ;
301301 let resolveReadyPromise : ( result : { success : boolean ; dataReadyPromise : Promise < any > } ) => void ;
302- const readyPromise : Promise < any > = new Promise ( res => {
302+ const readyPromise : Promise < any > = new Promise ( ( res ) => {
303303 resolveReadyPromise = ( result ) : void => {
304304 readySuccess = true ;
305305 res ( result ) ;
@@ -472,13 +472,13 @@ describe('hooks', () => {
472472 isFeatureEnabledMock . mockReturnValue ( true ) ;
473473 featureVariables = mockFeatureVariables ;
474474 // Wait for completion of dataReadyPromise
475- await optimizelyMock . onReady ( ) . then ( res => res . dataReadyPromise ) ;
475+ await optimizelyMock . onReady ( ) . then ( ( res ) => res . dataReadyPromise ) ;
476476
477477 // Simulate datafile fetch completing after timeout has already passed
478478 // Activate now returns a variation
479479 activateMock . mockReturnValue ( '12345' ) ;
480480 // Wait for completion of dataReadyPromise
481- await optimizelyMock . onReady ( ) . then ( res => res . dataReadyPromise ) ;
481+ await optimizelyMock . onReady ( ) . then ( ( res ) => res . dataReadyPromise ) ;
482482 await waitFor ( ( ) => expect ( screen . getByTestId ( 'result' ) ) . toHaveTextContent ( 'true|{"foo":"bar"}|true|true' ) ) ; // when clientReady
483483 } ) ;
484484
@@ -522,7 +522,7 @@ describe('hooks', () => {
522522 featureVariables = mockFeatureVariables ;
523523 // Simulate the user object changing
524524 await act ( async ( ) => {
525- userUpdateCallbacks . forEach ( fn => fn ( ) ) ;
525+ userUpdateCallbacks . forEach ( ( fn ) => fn ( ) ) ;
526526 } ) ;
527527 await waitFor ( ( ) => expect ( screen . getByTestId ( 'result' ) ) . toHaveTextContent ( 'true|{"foo":"bar"}|true|false' ) ) ;
528528 } ) ;
@@ -546,7 +546,7 @@ describe('hooks', () => {
546546 featureVariables = mockFeatureVariables ;
547547 // Simulate the user object changing
548548 act ( ( ) => {
549- userUpdateCallbacks . forEach ( fn => fn ( ) ) ;
549+ userUpdateCallbacks . forEach ( ( fn ) => fn ( ) ) ;
550550 } ) ;
551551 // component.update();
552552 await waitFor ( ( ) => expect ( screen . getByTestId ( 'result' ) ) . toHaveTextContent ( 'false|{}|true|false' ) ) ;
@@ -567,7 +567,7 @@ describe('hooks', () => {
567567 it ( 'should re-render after the client becomes ready' , async ( ) => {
568568 readySuccess = false ;
569569 let resolveReadyPromise : ( result : { success : boolean ; dataReadyPromise : Promise < any > } ) => void ;
570- const readyPromise : Promise < any > = new Promise ( res => {
570+ const readyPromise : Promise < any > = new Promise ( ( res ) => {
571571 resolveReadyPromise = ( result ) : void => {
572572 readySuccess = true ;
573573 res ( result ) ;
@@ -731,11 +731,11 @@ describe('hooks', () => {
731731 variables : { foo : 'bar' } ,
732732 } ) ;
733733
734- await optimizelyMock . onReady ( ) . then ( res => res . dataReadyPromise ) ;
734+ await optimizelyMock . onReady ( ) . then ( ( res ) => res . dataReadyPromise ) ;
735735
736736 // Simulate datafile fetch completing after timeout has already passed
737737 // Wait for completion of dataReadyPromise
738- await optimizelyMock . onReady ( ) . then ( res => res . dataReadyPromise ) ;
738+ await optimizelyMock . onReady ( ) . then ( ( res ) => res . dataReadyPromise ) ;
739739
740740 await waitFor ( ( ) => expect ( screen . getByTestId ( 'result' ) ) . toHaveTextContent ( 'true|{"foo":"bar"}|true|true' ) ) ; // when clientReady
741741 } ) ;
@@ -781,7 +781,7 @@ describe('hooks', () => {
781781 } ) ;
782782 // Simulate the user object changing
783783 await act ( async ( ) => {
784- userUpdateCallbacks . forEach ( fn => fn ( ) ) ;
784+ userUpdateCallbacks . forEach ( ( fn ) => fn ( ) ) ;
785785 } ) ;
786786 await waitFor ( ( ) => expect ( screen . getByTestId ( 'result' ) ) . toHaveTextContent ( 'true|{"foo":"bar"}|true|false' ) ) ;
787787 } ) ;
@@ -806,7 +806,7 @@ describe('hooks', () => {
806806 } ) ;
807807 // Simulate the user object changing
808808 await act ( async ( ) => {
809- userUpdateCallbacks . forEach ( fn => fn ( ) ) ;
809+ userUpdateCallbacks . forEach ( ( fn ) => fn ( ) ) ;
810810 } ) ;
811811 await waitFor ( ( ) => expect ( screen . getByTestId ( 'result' ) ) . toHaveTextContent ( 'false|{}|true|false' ) ) ;
812812 } ) ;
@@ -827,7 +827,7 @@ describe('hooks', () => {
827827 it ( 'should re-render after the client becomes ready' , async ( ) => {
828828 readySuccess = false ;
829829 let resolveReadyPromise : ( result : { success : boolean ; dataReadyPromise : Promise < any > } ) => void ;
830- const readyPromise : Promise < any > = new Promise ( res => {
830+ const readyPromise : Promise < any > = new Promise ( ( res ) => {
831831 resolveReadyPromise = ( result ) : void => {
832832 readySuccess = true ;
833833 res ( result ) ;
0 commit comments