|
1 | 1 | import * as React from 'react';
|
2 |
| -import { View } from 'react-native'; |
| 2 | +import { TextInput, View } from 'react-native'; |
3 | 3 | import { render, screen } from '../..';
|
4 |
| -import { getTextInputValue, isTextInputEditable } from '../text-input'; |
| 4 | +import { getTextInputValue, isEditableTextInput } from '../text-input'; |
5 | 5 |
|
6 |
| -test('getTextInputValue() throws error when invoked on non-text input', () => { |
7 |
| - render(<View testID="view" />); |
| 6 | +test('getTextInputValue basic test', () => { |
| 7 | + render( |
| 8 | + <View> |
| 9 | + <TextInput testID="value" value="text-a" /> |
| 10 | + <TextInput testID="default-value" defaultValue="text-b" /> |
| 11 | + <View testID="view" /> |
| 12 | + </View>, |
| 13 | + ); |
| 14 | + |
| 15 | + expect(getTextInputValue(screen.getByTestId('value'))).toBe('text-a'); |
| 16 | + expect(getTextInputValue(screen.getByTestId('default-value'))).toBe('text-b'); |
8 | 17 |
|
9 | 18 | const view = screen.getByTestId('view');
|
10 | 19 | expect(() => getTextInputValue(view)).toThrowErrorMatchingInlineSnapshot(
|
11 | 20 | `"Element is not a "TextInput", but it has type "View"."`,
|
12 | 21 | );
|
13 | 22 | });
|
14 | 23 |
|
15 |
| -test('isTextInputEditable() throws error when invoked on non-text input', () => { |
16 |
| - render(<View testID="view" />); |
17 |
| - |
18 |
| - const view = screen.getByTestId('view'); |
19 |
| - expect(() => isTextInputEditable(view)).toThrowErrorMatchingInlineSnapshot( |
20 |
| - `"Element is not a "TextInput", but it has type "View"."`, |
| 24 | +test('isEditableTextInput basic test', () => { |
| 25 | + render( |
| 26 | + <View> |
| 27 | + <TextInput testID="default" /> |
| 28 | + <TextInput testID="editable" editable={true} /> |
| 29 | + <TextInput testID="non-editable" editable={false} /> |
| 30 | + <View testID="view" /> |
| 31 | + </View>, |
21 | 32 | );
|
| 33 | + |
| 34 | + expect(isEditableTextInput(screen.getByTestId('default'))).toBe(true); |
| 35 | + expect(isEditableTextInput(screen.getByTestId('editable'))).toBe(true); |
| 36 | + expect(isEditableTextInput(screen.getByTestId('non-editable'))).toBe(false); |
| 37 | + expect(isEditableTextInput(screen.getByTestId('view'))).toBe(false); |
22 | 38 | });
|
0 commit comments