Skip to content

Commit 7e2c7c8

Browse files
Updated RNTL test config
1 parent 5b8bac1 commit 7e2c7c8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

images/rntl/rntl.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
});

0 commit comments

Comments
 (0)