Skip to content

Commit bab020c

Browse files
chore: improve example apps using skill (#1878)
1 parent 88954e8 commit bab020c

File tree

11 files changed

+25
-31
lines changed

11 files changed

+25
-31
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 & 10 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,23 +45,18 @@ 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

59-
<Pressable
60-
accessibilityRole="button"
61-
disabled={isLoading}
62-
onPress={handleSignIn}
63-
style={styles.button}
64-
>
59+
<Pressable role="button" disabled={isLoading} onPress={handleSignIn} style={styles.button}>
6560
{isLoading ? (
6661
<ActivityIndicator color="white" />
6762
) : (

examples/basic/components/__tests__/AnimatedView.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('AnimatedView', () => {
3333
);
3434
expect(screen.root).toHaveStyle({ opacity: 0 });
3535

36-
await act(() => jest.advanceTimersByTime(250));
36+
await act(() => jest.advanceTimersByTimeAsync(250));
3737
expect(screen.root).toHaveStyle({ opacity: 1 });
3838
});
3939
});

examples/basic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"@testing-library/react-native": "^14.0.0-beta.0",
2525
"@types/jest": "^29.5.12",
2626
"@types/react": "~19.1.10",
27-
"eslint": "^9.0.0",
27+
"eslint": "9.39.2",
2828
"eslint-plugin-testing-library": "^7.1.1",
2929
"jest": "^29.7.0",
3030
"test-renderer": "0.14.0",

examples/basic/yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3941,7 +3941,7 @@ __metadata:
39413941
languageName: node
39423942
linkType: hard
39433943

3944-
"eslint@npm:^9.0.0":
3944+
"eslint@npm:9.39.2":
39453945
version: 9.39.2
39463946
resolution: "eslint@npm:9.39.2"
39473947
dependencies:
@@ -7378,7 +7378,7 @@ __metadata:
73787378
"@testing-library/react-native": "npm:^14.0.0-beta.0"
73797379
"@types/jest": "npm:^29.5.12"
73807380
"@types/react": "npm:~19.1.10"
7381-
eslint: "npm:^9.0.0"
7381+
eslint: "npm:9.39.2"
73827382
eslint-plugin-testing-library: "npm:^7.1.1"
73837383
expo: "npm:^54.0.32"
73847384
expo-status-bar: "npm:~3.0.9"

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>

0 commit comments

Comments
 (0)