Skip to content

Commit c4514e1

Browse files
committed
improve example apps
1 parent 88954e8 commit c4514e1

File tree

8 files changed

+21
-22
lines changed

8 files changed

+21
-22
lines changed

examples/basic/__tests__/App.test.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test('renders correctly', async () => {
1313

1414
// Idiom: `getBy*` queries are predicates by themselves, but we will use it with `expect().toBeOnTheScreen()`
1515
// to clarify our intent.
16-
expect(screen.getByRole('header', { name: 'Sign in to Example App' })).toBeOnTheScreen();
16+
expect(screen.getByRole('heading', { name: 'Sign in to Example App' })).toBeOnTheScreen();
1717
});
1818

1919
/**
@@ -30,7 +30,7 @@ test('User can sign in successully with correct credentials', async () => {
3030

3131
// Idiom: `getBy*` queries are predicates by themselves, but we will use it with `expect().toBeOnTheScreen()`
3232
// to clarify our intent.
33-
expect(screen.getByRole('header', { name: 'Sign in to Example App' })).toBeOnTheScreen();
33+
expect(screen.getByRole('heading', { name: 'Sign in to Example App' })).toBeOnTheScreen();
3434

3535
// Hint: we can use `getByLabelText` to find our text inputs using their labels.
3636
await user.type(screen.getByLabelText('Username'), 'admin');
@@ -43,10 +43,10 @@ test('User can sign in successully with correct credentials', async () => {
4343
// for the action to complete.
4444
// Hint: subsequent queries do not need to use `findBy*`, because they are used after the async action
4545
// already finished
46-
expect(await screen.findByRole('header', { name: 'Welcome admin!' })).toBeOnTheScreen();
46+
expect(await screen.findByRole('heading', { name: 'Welcome admin!' })).toBeOnTheScreen();
4747

4848
// Idiom: use `queryBy*` with `expect().not.toBeOnTheScreen()` to assess that element is not present.
49-
expect(screen.queryByRole('header', { name: 'Sign in to Example App' })).not.toBeOnTheScreen();
49+
expect(screen.queryByRole('heading', { name: 'Sign in to Example App' })).not.toBeOnTheScreen();
5050
expect(screen.queryByLabelText('Username')).not.toBeOnTheScreen();
5151
expect(screen.queryByLabelText('Password')).not.toBeOnTheScreen();
5252
});
@@ -67,7 +67,7 @@ test('User will see errors for incorrect credentials', async () => {
6767
const user = userEvent.setup();
6868
await render(<App />);
6969

70-
expect(screen.getByRole('header', { name: 'Sign in to Example App' })).toBeOnTheScreen();
70+
expect(screen.getByRole('heading', { name: 'Sign in to Example App' })).toBeOnTheScreen();
7171

7272
await user.type(screen.getByLabelText('Username'), 'admin');
7373
await user.type(screen.getByLabelText('Password'), 'qwerty123');
@@ -76,7 +76,7 @@ test('User will see errors for incorrect credentials', async () => {
7676
// Hint: you can use custom Jest Native matcher to check text content.
7777
expect(await screen.findByRole('alert')).toHaveTextContent('Incorrect username or password');
7878

79-
expect(screen.getByRole('header', { name: 'Sign in to Example App' })).toBeOnTheScreen();
79+
expect(screen.getByRole('heading', { name: 'Sign in to Example App' })).toBeOnTheScreen();
8080
expect(screen.getByLabelText('Username')).toBeOnTheScreen();
8181
expect(screen.getByLabelText('Password')).toBeOnTheScreen();
8282
});
@@ -88,7 +88,7 @@ test('User can sign in after incorrect attempt', async () => {
8888
const user = userEvent.setup();
8989
await render(<App />);
9090

91-
expect(screen.getByRole('header', { name: 'Sign in to Example App' })).toBeOnTheScreen();
91+
expect(screen.getByRole('heading', { name: 'Sign in to Example App' })).toBeOnTheScreen();
9292

9393
const usernameInput = screen.getByLabelText('Username');
9494
const passwordInput = screen.getByLabelText('Password');
@@ -105,8 +105,8 @@ test('User can sign in after incorrect attempt', async () => {
105105
await user.type(passwordInput, 'admin1');
106106
await user.press(screen.getByRole('button', { name: 'Sign In' }));
107107

108-
expect(await screen.findByText('Welcome admin!')).toBeOnTheScreen();
109-
expect(screen.queryByRole('header', { name: 'Sign in to Example App' })).not.toBeOnTheScreen();
108+
expect(await screen.findByRole('heading', { name: 'Welcome admin!' })).toBeOnTheScreen();
109+
expect(screen.queryByRole('heading', { name: 'Sign in to Example App' })).not.toBeOnTheScreen();
110110
expect(screen.queryByLabelText('Username')).not.toBeOnTheScreen();
111111
expect(screen.queryByLabelText('Password')).not.toBeOnTheScreen();
112112
});

examples/basic/components/Home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Props = {
88
export function Home({ user }: Props) {
99
return (
1010
<View style={styles.container}>
11-
<Text accessibilityRole="header" style={styles.title}>
11+
<Text role="heading" style={styles.title}>
1212
Welcome {user}!
1313
</Text>
1414
</View>

examples/basic/components/LoginForm.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ export function LoginForm({ onLoginSuccess }: Props) {
2828

2929
return (
3030
<View style={styles.container}>
31-
<Text accessibilityRole="header" style={styles.title}>
31+
<Text role="heading" style={styles.title}>
3232
Sign in to Example App
3333
</Text>
3434

3535
<Text style={styles.textLabel}>Username</Text>
3636
<TextInput
3737
value={username}
3838
onChangeText={setUsername}
39-
accessibilityLabel="Username"
39+
aria-label="Username"
4040
autoCapitalize="none"
4141
style={styles.textInput}
4242
/>
@@ -45,19 +45,19 @@ export function LoginForm({ onLoginSuccess }: Props) {
4545
<TextInput
4646
value={password}
4747
onChangeText={setPassword}
48-
accessibilityLabel="Password"
48+
aria-label="Password"
4949
secureTextEntry={true}
5050
style={styles.textInput}
5151
/>
5252

5353
{error && (
54-
<Text accessibilityRole="alert" style={styles.validator}>
54+
<Text role="alert" style={styles.validator}>
5555
{error}
5656
</Text>
5757
)}
5858

5959
<Pressable
60-
accessibilityRole="button"
60+
role="button"
6161
disabled={isLoading}
6262
onPress={handleSignIn}
6363
style={styles.button}

examples/cookbook/app/network-requests/__tests__/PhoneBook.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, screen, waitForElementToBeRemoved } from '@testing-library/react-native';
1+
import { render, screen } from '@testing-library/react-native';
22
import React from 'react';
33
import PhoneBook from '../PhoneBook';
44
import {

examples/cookbook/app/network-requests/components/FavoritesList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default ({ users }: { users: User[] }) => {
1010
<Image
1111
source={{ uri: picture.thumbnail }}
1212
style={styles.userImage}
13-
accessibilityLabel={'favorite-contact-avatar'}
13+
aria-label="favorite-contact-avatar"
1414
/>
1515
</View>
1616
);

examples/cookbook/app/state-management/jotai/TaskList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ export function TaskList() {
3131
{!tasks.length ? <Text>No tasks, start by adding one...</Text> : null}
3232

3333
<TextInput
34-
accessibilityLabel="New Task"
34+
aria-label="New Task"
3535
placeholder="New Task..."
3636
value={newTaskTitle}
3737
onChangeText={(text) => setNewTaskTitle(text)}
3838
/>
3939

40-
<Pressable accessibilityRole="button" onPress={handleAddTask}>
40+
<Pressable role="button" onPress={handleAddTask}>
4141
<Text>Add Task</Text>
4242
</Pressable>
4343
</View>

examples/cookbook/basics-tutorial-react-strict-dom/3-jest-matchers-rsd.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test('showcase: toBeOnTheScreen', async () => {
1313
expect(screen.queryByTestId('non-existent')).not.toBeOnTheScreen();
1414
});
1515

16-
test('showcase: toBeIntoHaveTextContentTheDocument', async () => {
16+
test('showcase: toHaveTextContent', async () => {
1717
await render(
1818
<html.div>
1919
<html.p data-testid="text">Hello World</html.p>

examples/cookbook/basics-tutorial/3-jest-matchers.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import * as React from 'react';
1818
import { render, screen } from '@testing-library/react-native';
1919
import { Text, TextInput, View } from 'react-native';
20-
import { s } from 'react-strict-dom/runtime';
2120

2221
/**
2322
* MATCHER 1: toBeOnTheScreen()
@@ -57,7 +56,7 @@ test('showcase: toBeOnTheScreen', async () => {
5756
* - expect(element).toHaveTextContent(/pattern/i) - regex with case-insensitive flag
5857
* - expect(element).toHaveTextContent('partial', { exact: false })
5958
*/
60-
test('showcase: toBeIntoHaveTextContentTheDocument', async () => {
59+
test('showcase: toHaveTextContent', async () => {
6160
await render(
6261
<View>
6362
<Text testID="text">Hello World</Text>

0 commit comments

Comments
 (0)