File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ import React from "react" ;
2
+ import { render , screen , userEvent } from "@testing-library/react-native" ;
3
+ import UserEventTest from "../src/screens/testScreens/userEventTest.screen" ;
4
+
5
+ describe ( "Test using UserEvent" , ( ) => {
6
+ it ( "should render the TEST Screen" , async ( ) => {
7
+ // Enable fakeTimers
8
+ jest . useFakeTimers ( ) ;
9
+
10
+ // Setup UserEvent
11
+ const user = userEvent . setup ( {
12
+ delay : null ,
13
+ advanceTimers : ( delay ) => jest . advanceTimersByTime ( 10000 ) ,
14
+ } ) ;
15
+
16
+ // Render the Screen
17
+ render ( < UserEventTest /> ) ;
18
+
19
+ // Get the BUTTON with the testID "button"
20
+ const button = screen . getByTestId ( "button" ) ;
21
+
22
+ // Each time you will call a "UserEvent" method like below,
23
+ // it will trigger this line "jest.advanceTimersByTime(10000)"
24
+ await user . longPress ( button ) ;
25
+
26
+ // Get the TEXT with the testID "textConditional"
27
+ const textConditional = screen . queryByTestId ( "textConditional" ) ;
28
+
29
+ // Expect the element to contain "Text Visible"
30
+ expect ( textConditional ) . toHaveTextContent ( "Text Visible" ) ;
31
+ } ) ;
32
+ } ) ;
You can’t perform that action at this time.
0 commit comments