11import React from 'react' ;
2- import { Image , LayoutChangeEvent , Pressable , Text , View } from 'react-native' ;
3- import '@testing-library/jest-native/extend-expect' ;
2+ import {
3+ Image ,
4+ LayoutChangeEvent ,
5+ Platform ,
6+ Pressable ,
7+ StatusBar ,
8+ Text ,
9+ View ,
10+ } from 'react-native' ;
411import {
512 render ,
613 act ,
@@ -131,7 +138,7 @@ test('onDismissProgrammatic', async () => {
131138 /> ,
132139 ) ;
133140 expect ( component ) . toBeDefined ( ) ;
134- await act ( ( ) => {
141+ act ( ( ) => {
135142 alert ( {
136143 type : 'custom' ,
137144 title : DropDownAlertTestID . Title ,
@@ -148,7 +155,7 @@ test('onDismissProgrammatic', async () => {
148155 dismiss ( ) ;
149156 await delay ( ) ;
150157 } ) ;
151- expect ( _onDismissProgrammatic ) . toBeCalled ( ) ;
158+ expect ( _onDismissProgrammatic ) . toHaveBeenCalled ( ) ;
152159} , 2000 ) ;
153160
154161test ( 'onDismissPress' , async ( ) => {
@@ -180,7 +187,7 @@ test('onDismissPress', async () => {
180187 fireEvent . press ( button ) ;
181188 await delay ( ) ;
182189 } ) ;
183- expect ( _onDismissPress ) . toBeCalled ( ) ;
190+ expect ( _onDismissPress ) . toHaveBeenCalled ( ) ;
184191} , 2000 ) ;
185192
186193test ( 'onDismissCancel' , async ( ) => {
@@ -211,7 +218,7 @@ test('onDismissCancel', async () => {
211218 expect ( cancelImage ) . toBeDefined ( ) ;
212219 await delay ( ) ;
213220 } ) ;
214- expect ( _onDismissCancel ) . toBeCalled ( ) ;
221+ expect ( _onDismissCancel ) . toHaveBeenCalled ( ) ;
215222} , 5500 ) ;
216223
217224test ( 'renderImage, renderTitle, renderMessage and renderCancel props' , async ( ) => {
@@ -281,16 +288,30 @@ test('Animated.View onLayout function', async () => {
281288 < DropdownAlert alert = { func => ( alert = func ) } dismissInterval = { 0 } /> ,
282289 ) ;
283290 expect ( component ) . toBeDefined ( ) ;
284- await act ( ( ) => {
291+ act ( ( ) => {
285292 alert ( { type : DropdownAlertType . Warn , title : 'title' , message : 'message' } ) ;
286293 } ) ;
287294 const height = 150 ;
288295 const animatedView = screen . getByTestId ( DropDownAlertTestID . AnimatedView ) ;
289296 expect ( animatedView ) . toBeDefined ( ) ;
290297 const event : LayoutChangeEvent = {
291298 nativeEvent : { layout : { x : 0 , y : 0 , height, width : 100 } } ,
292- currentTarget : 0 ,
293- target : 0 ,
299+ currentTarget : {
300+ measure : jest . fn ( ) ,
301+ measureInWindow : jest . fn ( ) ,
302+ measureLayout : jest . fn ( ) ,
303+ setNativeProps : jest . fn ( ) ,
304+ focus : jest . fn ( ) ,
305+ blur : jest . fn ( ) ,
306+ } ,
307+ target : {
308+ measure : jest . fn ( ) ,
309+ measureInWindow : jest . fn ( ) ,
310+ measureLayout : jest . fn ( ) ,
311+ setNativeProps : jest . fn ( ) ,
312+ focus : jest . fn ( ) ,
313+ blur : jest . fn ( ) ,
314+ } ,
294315 bubbles : false ,
295316 cancelable : false ,
296317 defaultPrevented : false ,
@@ -319,17 +340,7 @@ test('Animated.View onLayout function', async () => {
319340} ) ;
320341
321342test ( 'it updates status bar on Android' , async ( ) => {
322- jest . mock ( 'react-native/Libraries/Utilities/Platform' , ( ) => ( {
323- OS : 'android' ,
324- select : ( ) => null ,
325- } ) ) ;
326- const currentHeight = 20 ;
327- jest . mock ( 'react-native/Libraries/Components/StatusBar/StatusBar' , ( ) => ( {
328- currentHeight,
329- setBackgroundColor : jest . fn ( ) ,
330- setTranslucent : jest . fn ( ) ,
331- setBarStyle : jest . fn ( ) ,
332- } ) ) ;
343+ Platform . OS = 'android' ;
333344 let alert = ( _data ?: DropdownAlertData ) =>
334345 new Promise < DropdownAlertData > ( res => res ) ;
335346 const component = render (
@@ -341,22 +352,12 @@ test('it updates status bar on Android', async () => {
341352 } ) ;
342353 const button = screen . getByTestId ( DropDownAlertTestID . Alert ) ;
343354 expect ( button ) . toBeDefined ( ) ;
344- expect ( button ) . toHaveStyle ( { marginTop : currentHeight } ) ;
355+ expect ( button ) . toHaveStyle ( { marginTop : StatusBar . currentHeight } ) ;
345356 expect ( component . toJSON ( ) ) . toMatchSnapshot ( ) ;
346357} , 6000 ) ;
347358
348359test ( 'it updates status bar with containerStyle undefined backgroundColor on Android' , async ( ) => {
349- jest . mock ( 'react-native/Libraries/Utilities/Platform' , ( ) => ( {
350- OS : 'android' ,
351- select : ( ) => null ,
352- } ) ) ;
353- const currentHeight = 20 ;
354- jest . mock ( 'react-native/Libraries/Components/StatusBar/StatusBar' , ( ) => ( {
355- currentHeight,
356- setBackgroundColor : jest . fn ( ) ,
357- setTranslucent : jest . fn ( ) ,
358- setBarStyle : jest . fn ( ) ,
359- } ) ) ;
360+ Platform . OS = 'android' ;
360361 let alert = ( _data ?: DropdownAlertData ) =>
361362 new Promise < DropdownAlertData > ( res => res ) ;
362363 const component = render (
@@ -372,7 +373,8 @@ test('it updates status bar with containerStyle undefined backgroundColor on And
372373 } ) ;
373374 const button = screen . getByTestId ( DropDownAlertTestID . Alert ) ;
374375 expect ( button ) . toBeDefined ( ) ;
375- expect ( button ) . toHaveStyle ( { marginTop : currentHeight } ) ;
376+ expect ( button ) . toHaveStyle ( { marginTop : StatusBar . currentHeight } ) ;
377+ expect ( component . toJSON ( ) ) . toMatchSnapshot ( ) ;
376378} , 6000 ) ;
377379
378380test ( 'children prop' , async ( ) => {
0 commit comments