13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- /// <reference types="jest" />
16
+ import { describe , beforeEach , afterEach , it , expect , vi } from 'vitest' ;
17
+
17
18
import * as logging from '../lib/modules/logging/logger' ;
18
19
import * as eventProcessor from '../lib//plugins/event_processor/index.react_native' ;
19
20
@@ -24,17 +25,18 @@ import optimizelyFactory from '../lib/index.react_native';
24
25
import configValidator from '../lib/utils/config_validator' ;
25
26
import eventProcessorConfigValidator from '../lib/utils/event_processor_config_validator' ;
26
27
27
- jest . mock ( 'react-native-get-random-values' )
28
- jest . mock ( 'fast-text-encoding' )
28
+ vi . mock ( '@react-native-community/netinfo' ) ;
29
+ vi . mock ( 'react-native-get-random-values' )
30
+ vi . mock ( 'fast-text-encoding' )
29
31
30
32
describe ( 'javascript-sdk/react-native' , ( ) => {
31
33
beforeEach ( ( ) => {
32
- jest . spyOn ( optimizelyFactory . eventDispatcher , 'dispatchEvent' ) ;
33
- jest . useFakeTimers ( ) ;
34
+ vi . spyOn ( optimizelyFactory . eventDispatcher , 'dispatchEvent' ) ;
35
+ vi . useFakeTimers ( ) ;
34
36
} ) ;
35
37
36
38
afterEach ( ( ) => {
37
- jest . resetAllMocks ( ) ;
39
+ vi . resetAllMocks ( ) ;
38
40
} ) ;
39
41
40
42
describe ( 'APIs' , ( ) => {
@@ -56,14 +58,14 @@ describe('javascript-sdk/react-native', () => {
56
58
beforeEach ( ( ) => {
57
59
// @ts -ignore
58
60
silentLogger = optimizelyFactory . logging . createLogger ( ) ;
59
- jest . spyOn ( console , 'error' ) ;
60
- jest . spyOn ( configValidator , 'validate' ) . mockImplementation ( ( ) => {
61
+ vi . spyOn ( console , 'error' ) ;
62
+ vi . spyOn ( configValidator , 'validate' ) . mockImplementation ( ( ) => {
61
63
throw new Error ( 'Invalid config or something' ) ;
62
64
} ) ;
63
65
} ) ;
64
66
65
67
afterEach ( ( ) => {
66
- jest . resetAllMocks ( ) ;
68
+ vi . resetAllMocks ( ) ;
67
69
} ) ;
68
70
69
71
it ( 'should not throw if the provided config is not valid' , ( ) => {
@@ -131,11 +133,11 @@ describe('javascript-sdk/react-native', () => {
131
133
132
134
describe ( 'when passing in logLevel' , ( ) => {
133
135
beforeEach ( ( ) => {
134
- jest . spyOn ( logging , 'setLogLevel' ) ;
136
+ vi . spyOn ( logging , 'setLogLevel' ) ;
135
137
} ) ;
136
138
137
139
afterEach ( ( ) => {
138
- jest . resetAllMocks ( ) ;
140
+ vi . resetAllMocks ( ) ;
139
141
} ) ;
140
142
141
143
it ( 'should call logging.setLogLevel' , ( ) => {
@@ -150,11 +152,11 @@ describe('javascript-sdk/react-native', () => {
150
152
151
153
describe ( 'when passing in logger' , ( ) => {
152
154
beforeEach ( ( ) => {
153
- jest . spyOn ( logging , 'setLogHandler' ) ;
155
+ vi . spyOn ( logging , 'setLogHandler' ) ;
154
156
} ) ;
155
157
156
158
afterEach ( ( ) => {
157
- jest . resetAllMocks ( ) ;
159
+ vi . resetAllMocks ( ) ;
158
160
} ) ;
159
161
160
162
it ( 'should call logging.setLogHandler with the supplied logger' , ( ) => {
@@ -173,11 +175,11 @@ describe('javascript-sdk/react-native', () => {
173
175
// @ts -ignore
174
176
let eventProcessorSpy ;
175
177
beforeEach ( ( ) => {
176
- eventProcessorSpy = jest . spyOn ( eventProcessor , 'createEventProcessor' ) ;
178
+ eventProcessorSpy = vi . spyOn ( eventProcessor , 'createEventProcessor' ) ;
177
179
} ) ;
178
180
179
181
afterEach ( ( ) => {
180
- jest . resetAllMocks ( ) ;
182
+ vi . resetAllMocks ( ) ;
181
183
} ) ;
182
184
183
185
it ( 'should use default event flush interval when none is provided' , ( ) => {
@@ -201,11 +203,11 @@ describe('javascript-sdk/react-native', () => {
201
203
202
204
describe ( 'with an invalid flush interval' , ( ) => {
203
205
beforeEach ( ( ) => {
204
- jest . spyOn ( eventProcessorConfigValidator , 'validateEventFlushInterval' ) . mockImplementation ( ( ) => false ) ;
206
+ vi . spyOn ( eventProcessorConfigValidator , 'validateEventFlushInterval' ) . mockImplementation ( ( ) => false ) ;
205
207
} ) ;
206
208
207
209
afterEach ( ( ) => {
208
- jest . resetAllMocks ( ) ;
210
+ vi . resetAllMocks ( ) ;
209
211
} ) ;
210
212
211
213
it ( 'should ignore the event flush interval and use the default instead' , ( ) => {
@@ -231,11 +233,11 @@ describe('javascript-sdk/react-native', () => {
231
233
232
234
describe ( 'with a valid flush interval' , ( ) => {
233
235
beforeEach ( ( ) => {
234
- jest . spyOn ( eventProcessorConfigValidator , 'validateEventFlushInterval' ) . mockImplementation ( ( ) => true ) ;
236
+ vi . spyOn ( eventProcessorConfigValidator , 'validateEventFlushInterval' ) . mockImplementation ( ( ) => true ) ;
235
237
} ) ;
236
238
237
239
afterEach ( ( ) => {
238
- jest . resetAllMocks ( ) ;
240
+ vi . resetAllMocks ( ) ;
239
241
} ) ;
240
242
241
243
it ( 'should use the provided event flush interval' , ( ) => {
@@ -278,11 +280,11 @@ describe('javascript-sdk/react-native', () => {
278
280
279
281
describe ( 'with an invalid event batch size' , ( ) => {
280
282
beforeEach ( ( ) => {
281
- jest . spyOn ( eventProcessorConfigValidator , 'validateEventBatchSize' ) . mockImplementation ( ( ) => false ) ;
283
+ vi . spyOn ( eventProcessorConfigValidator , 'validateEventBatchSize' ) . mockImplementation ( ( ) => false ) ;
282
284
} ) ;
283
285
284
286
afterEach ( ( ) => {
285
- jest . resetAllMocks ( ) ;
287
+ vi . resetAllMocks ( ) ;
286
288
} ) ;
287
289
288
290
it ( 'should ignore the event batch size and use the default instead' , ( ) => {
@@ -308,11 +310,11 @@ describe('javascript-sdk/react-native', () => {
308
310
309
311
describe ( 'with a valid event batch size' , ( ) => {
310
312
beforeEach ( ( ) => {
311
- jest . spyOn ( eventProcessorConfigValidator , 'validateEventBatchSize' ) . mockImplementation ( ( ) => true ) ;
313
+ vi . spyOn ( eventProcessorConfigValidator , 'validateEventBatchSize' ) . mockImplementation ( ( ) => true ) ;
312
314
} ) ;
313
315
314
316
afterEach ( ( ) => {
315
- jest . resetAllMocks ( ) ;
317
+ vi . resetAllMocks ( ) ;
316
318
} ) ;
317
319
318
320
it ( 'should use the provided event batch size' , ( ) => {
0 commit comments