11import "../../src/register" ;
22
33import { expect } from "@assertive-ts/core" ;
4- import { render } from "@testing-library/react-native" ;
5- import { ActivityIndicator , Image , Modal , ScrollView , Text , TextInput , View } from "react-native" ;
4+ import { render , waitFor , userEvent } from "@testing-library/react-native" ;
5+ import { ReactElement , useCallback , useRef , useState } from "react" ;
6+ import { ActivityIndicator , Animated , Button , Image , Modal , ScrollView , Text , TextInput , View } from "react-native" ;
7+
8+ function TestScreen ( ) : ReactElement {
9+
10+ const [ animated , setAnimated ] = useState ( false ) ;
11+
12+ const enterLeft = useRef ( new Animated . Value ( 100 , { useNativeDriver : true } ) ) . current ;
13+ const movePoint = useRef ( new Animated . ValueXY ( { x : 0 , y : 0 } , { useNativeDriver : true } ) ) . current ;
14+
15+ const animateView = useCallback ( ( ) => {
16+ const enterAnim = Animated . timing ( enterLeft , {
17+ duration : 100 ,
18+ toValue : 0 ,
19+ useNativeDriver : true ,
20+ } ) ;
21+ const moveAnim = Animated . spring ( movePoint , {
22+ damping : 45 ,
23+ mass : 4 ,
24+ stiffness : 350 ,
25+ toValue : { x : 50 , y : 10 } ,
26+ useNativeDriver : true ,
27+ } ) ;
28+
29+ Animated . parallel ( [ enterAnim , moveAnim ] ) . start ( ( { finished } ) => {
30+ setAnimated ( finished ) ;
31+ } ) ;
32+ } , [ ] ) ;
33+
34+ return (
35+ < ScrollView >
36+ < View >
37+ < ActivityIndicator aria-label = "Loading" animating = { true } />
38+ < Text > { "Hello world!" } </ Text >
39+ < TextInput placeholder = "Say hello here..." value = "Hello :)" />
40+ < Image alt = "Profile picture" />
41+ < Modal visible = { true } >
42+ < Text > { "I'm on a modal" } </ Text >
43+ </ Modal >
44+ < Modal visible = { false } >
45+ < Text > { "foo" } </ Text >
46+ </ Modal >
47+ </ View >
48+ < Button title = "Click Me!" onPress = { animateView } />
49+ < Animated . View style = { { marginLeft : enterLeft } } >
50+ < Text > { `Animated view: ${ animated } ` } </ Text >
51+ </ Animated . View >
52+ </ ScrollView >
53+ ) ;
54+ }
655
756describe ( "[Unit] register.test.ts" , ( ) => {
857 context ( "when main is called" , ( ) => {
9- it ( "mocks react native so it can render on Node.js" , ( ) => {
58+ it ( "mocks react native so it can render on Node.js" , async ( ) => {
1059 const {
1160 getByText,
1261 getByPlaceholderText,
1362 getByDisplayValue,
1463 getByLabelText,
15- } = render (
16- < ScrollView >
17- < View >
18- < ActivityIndicator aria-label = "Loading" animating = { true } />
19- < Text > { "Hello world!" } </ Text >
20- < TextInput placeholder = "Say hello here..." value = "Hello :)" />
21- < Image alt = "Profile picture" />
22- < Modal visible = { true } >
23- < Text > { "I'm on a modal" } </ Text >
24- </ Modal >
25- < Modal visible = { false } >
26- < Text > { "foo" } </ Text >
27- </ Modal >
28- </ View >
29- </ ScrollView > ,
30- ) ;
64+ findByText,
65+ } = render ( < TestScreen /> ) ;
3166
3267 expect ( getByLabelText ( "Loading" ) ) . toBePresent ( ) ;
3368 expect ( getByText ( "Hello world!" ) ) . toBePresent ( ) ;
@@ -36,6 +71,13 @@ describe("[Unit] register.test.ts", () => {
3671 expect ( getByLabelText ( "Profile picture" ) ) . toBePresent ( ) ;
3772 expect ( getByText ( "I'm on a modal" ) ) . toBePresent ( ) ;
3873 expect ( ( ) => getByText ( "foo" ) ) . toThrowError ( ) ;
74+ expect ( getByText ( "Animated view: false" ) ) . toBePresent ( ) ;
75+
76+ const clickMeButton = await findByText ( "Click Me!" ) ;
77+
78+ await userEvent . press ( clickMeButton ) ;
79+
80+ await waitFor ( ( ) => getByText ( "Animated view: true" ) ) ;
3981 } ) ;
4082 } ) ;
4183} ) ;
0 commit comments