(this: UserEventInstance, instance: TestInstance)
| 15 | import { dispatchEvent, wait } from './utils'; |
| 16 | |
| 17 | export async function clear(this: UserEventInstance, instance: TestInstance): Promise<void> { |
| 18 | if (!isHostTextInput(instance)) { |
| 19 | throw new ErrorWithStack( |
| 20 | `clear() only supports host "TextInput" instances. Passed instance has type: "${instance.type}".`, |
| 21 | clear, |
| 22 | ); |
| 23 | } |
| 24 | |
| 25 | if (!isEditableTextInput(instance) || !isPointerEventEnabled(instance)) { |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | // 1. Enter instance |
| 30 | await dispatchEvent(instance, 'focus', buildFocusEvent()); |
| 31 | |
| 32 | // 2. Select all |
| 33 | const textToClear = getTextInputValue(instance); |
| 34 | const selectionRange = { |
| 35 | start: 0, |
| 36 | end: textToClear.length, |
| 37 | }; |
| 38 | await dispatchEvent(instance, 'selectionChange', buildTextSelectionChangeEvent(selectionRange)); |
| 39 | |
| 40 | // 3. Press backspace with selected text |
| 41 | const emptyText = ''; |
| 42 | await emitTypingEvents(instance, { |
| 43 | config: this.config, |
| 44 | key: 'Backspace', |
| 45 | text: emptyText, |
| 46 | }); |
| 47 | |
| 48 | // 4. Exit instance |
| 49 | await wait(this.config); |
| 50 | await dispatchEvent(instance, 'endEditing', buildEndEditingEvent(emptyText)); |
| 51 | await dispatchEvent(instance, 'blur', buildBlurEvent()); |
| 52 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…