1
- import { fireEvent , render } from '@testing-library/react-native' ;
1
+ import { fireEvent , render , screen } from '@testing-library/react-native' ;
2
2
import React from 'react' ;
3
3
import { PressableProps , ViewProps } from 'react-native' ;
4
4
import Reanimated , { ZoomIn , ZoomOut } from 'react-native-reanimated' ;
@@ -32,35 +32,35 @@ const Wrapper: React.FC = ({children}) => {
32
32
33
33
describe ( 'OverlayBackdrop only with required props' , ( ) => {
34
34
it ( 'returns null if not visible' , ( ) => {
35
- const sut = render ( < OverlayBackdrop isVisible = { false } /> , { wrapper : Wrapper } ) ;
35
+ render ( < OverlayBackdrop isVisible = { false } /> , { wrapper : Wrapper } ) ;
36
36
// OverlayBackdropがnullを返していることを確認したいがうまくやる方法が見当たらないので`toJSON`でnullになることを確認する。
37
- expect ( sut . toJSON ( ) ) . toBeNull ( ) ;
37
+ expect ( screen . toJSON ( ) ) . toBeNull ( ) ;
38
38
} ) ;
39
39
40
40
it ( 'renders successfully only with required props' , ( ) => {
41
- const sut = render ( < OverlayBackdrop isVisible testID = "backdropAnimated" /> , { wrapper : Wrapper } ) ;
42
- const animatedView = sut . getByTestId ( 'backdropAnimated' ) ;
41
+ render ( < OverlayBackdrop isVisible testID = "backdropAnimated" /> , { wrapper : Wrapper } ) ;
42
+ const animatedView = screen . getByTestId ( 'backdropAnimated' ) ;
43
43
const animatedViewProps = animatedView . props as Reanimated . AnimateProps < ViewProps > ;
44
44
// Animated.Viewのentering/exitingをテストで実行することができなかったため、entering/exitingにデフォルトアニメーションが設定されていることのみを確認する。
45
- expect ( sut ) . toMatchSnapshot ( 'AnimatedView with visible.' ) ;
45
+ expect ( screen ) . toMatchSnapshot ( 'AnimatedView with visible.' ) ;
46
46
expect ( animatedView ) . not . toBeNull ( ) ;
47
47
expect ( animatedViewProps . entering ) . toBe ( OVERLAY_BACKDROP_DEFAULT_ENTERING ) ;
48
48
expect ( animatedViewProps . exiting ) . toBe ( OVERLAY_BACKDROP_DEFAULT_EXITING ) ;
49
49
50
50
//////////////////////////////////////////////////////////////////////////////////
51
51
// 非表示にする
52
52
//////////////////////////////////////////////////////////////////////////////////
53
- sut . update ( < OverlayBackdrop isVisible = { false } /> ) ;
54
- const animatedView2 = sut . queryByTestId ( 'backdropAnimated' ) ;
55
- expect ( sut ) . toMatchSnapshot ( 'AnimatedView with invisible.' ) ;
53
+ screen . update ( < OverlayBackdrop isVisible = { false } /> ) ;
54
+ const animatedView2 = screen . queryByTestId ( 'backdropAnimated' ) ;
55
+ expect ( screen ) . toMatchSnapshot ( 'AnimatedView with invisible.' ) ;
56
56
expect ( animatedView2 ) . toBeNull ( ) ;
57
57
} ) ;
58
58
} ) ;
59
59
60
60
describe ( 'OverlayBackdrop with `onPress' , ( ) => {
61
61
it ( 'should be called on pressed' , ( ) => {
62
62
const onPress = jest . fn ( ) ;
63
- const sut = render (
63
+ render (
64
64
< OverlayBackdrop
65
65
isVisible
66
66
onPress = { onPress }
@@ -70,7 +70,7 @@ describe('OverlayBackdrop with `onPress', () => {
70
70
/> ,
71
71
{ wrapper : Wrapper } ,
72
72
) ;
73
- fireEvent . press ( sut . getByTestId ( 'pressable' ) ) ;
73
+ fireEvent . press ( screen . getByTestId ( 'pressable' ) ) ;
74
74
expect ( onPress ) . toHaveBeenCalledTimes ( 1 ) ;
75
75
} ) ;
76
76
} ) ;
@@ -88,7 +88,7 @@ describe('OverlayBackdrop with all props', () => {
88
88
*
89
89
* animatedPropsは取得できなかったため(Snapshot上にも存在していない)、検証できていません
90
90
*/
91
- const sut = render (
91
+ render (
92
92
< OverlayBackdrop
93
93
isVisible
94
94
testID = "animatedView"
@@ -102,10 +102,10 @@ describe('OverlayBackdrop with all props', () => {
102
102
/> ,
103
103
{ wrapper : Wrapper } ,
104
104
) ;
105
- expect ( sut ) . toMatchSnapshot ( 'OverlayBackdrop with all props.' ) ;
106
- const modal = sut . getByTestId ( 'modal' ) ;
107
- const pressable = sut . getByTestId ( 'pressable' ) ;
108
- const animatedView = sut . getByTestId ( 'animatedView' ) ;
105
+ expect ( screen ) . toMatchSnapshot ( 'OverlayBackdrop with all props.' ) ;
106
+ const modal = screen . getByTestId ( 'modal' ) ;
107
+ const pressable = screen . getByTestId ( 'pressable' ) ;
108
+ const animatedView = screen . getByTestId ( 'animatedView' ) ;
109
109
110
110
// assert modal
111
111
const modalProps = modal . props as ViewProps ;
0 commit comments