Skip to content

Commit 7c59d6e

Browse files
committed
docs: improve the docs
1 parent d6f8fe1 commit 7c59d6e

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/user-event/setup/setup.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,20 @@ const defaultOptions: Required<UserEventSetupOptions> = {
4545
* Creates a new instance of user event instance with the given options.
4646
*
4747
* @param options
48-
* @returns
48+
* @returns UserEvent instance
4949
*/
5050
export function setup(options?: UserEventSetupOptions) {
5151
const config = createConfig(options);
5252
const instance = createInstance(config);
5353
return instance;
5454
}
5555

56+
/**
57+
* Options affecting all user event interactions.
58+
*
59+
* @param delay between some subsequent inputs like typing a series of characters
60+
* @param advanceTimers function to be called to advance fake timers
61+
*/
5662
export interface UserEventConfig {
5763
delay: number;
5864
advanceTimers: (delay: number) => Promise<void> | void;
@@ -65,9 +71,34 @@ function createConfig(options?: UserEventSetupOptions): UserEventConfig {
6571
};
6672
}
6773

74+
/**
75+
* UserEvent instance used to invoke user interaction functions.
76+
*/
6877
export interface UserEventInstance {
6978
config: UserEventConfig;
79+
7080
press: (element: ReactTestInstance) => Promise<void>;
81+
82+
/**
83+
* Simulate user pressing on given `TextInput` element and typing given text.
84+
*
85+
* This method will trigger the events for each character of the text:
86+
* `keyPress`, `change`, `changeText`, `endEditing`, etc.
87+
*
88+
* It will also trigger events connected with entering and leaving the text
89+
* input.
90+
*
91+
* The exact events sent depend on the props of TextInput (`editable`,
92+
* `multiline`, value, defaultValue, etc) and passed options.
93+
*
94+
* @param element TextInput element to type on
95+
* @param text Text to type
96+
* @param options Options affecting typing behavior:
97+
* - `skipPress` - if true, `pressIn` and `pressOut` events will not be
98+
* triggered.
99+
* - `submitEditing` - if true, `submitEditing` event will be triggered after
100+
* typing the text.
101+
*/
71102
type: (
72103
element: ReactTestInstance,
73104
text: string,

src/user-event/type/__tests__/type.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { View, TextInput, TextInputProps } from 'react-native';
33
import { createEventLogger } from '../../../test-utils/events';
44
import { render } from '../../..';
55
import { userEvent } from '../..';
6+
import { UserEventInstance } from '../../setup';
67

78
beforeEach(() => {
89
jest.useRealTimers();

website/docs/UserEvent.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ title: User Event
88
- [`userEvent.setup`](#usereventsetup)
99
- [Options](#options)
1010
- [`type()`](#type)
11+
- [Options:](#options-1)
1112
- [Sequence of events](#sequence-of-events)
1213

1314

@@ -44,10 +45,25 @@ type(
4445
): Promise<void>
4546
```
4647

48+
Example
49+
```ts
50+
await user.type(textInput, "Hello world!");
51+
```
52+
4753
This helper simulates user focusing on `TextInput` element, typing `text` one character at a time, and leaving the element.
4854

55+
This function supports only host `TextInput` elements. Passing other element type will result in throwing error.
56+
57+
### Options:
58+
- `skipPress` - if true, `pressIn` and `pressOut` events will not be triggered.
59+
- `submitEditing` - if true, `submitEditing` event will be triggered after typing the text.
60+
4961
### Sequence of events
5062

63+
The sequence of events depends on `multiline` prop, as well as passed options.
64+
65+
Events will not be emitted if `editable` prop is set to `false`.
66+
5167
Entering the element:
5268
- `pressIn` (optional)
5369
- `focus`

0 commit comments

Comments
 (0)