1
1
// @flow
2
2
import * as React from 'react' ;
3
3
import prettyFormat from 'pretty-format' ;
4
- import { filterNodeByType } from './filterNodeByType' ;
5
4
import {
6
5
ErrorWithStack ,
7
- createLibraryNotSupportedError ,
8
6
prepareErrorMessage ,
9
7
throwRemovedFunctionError ,
10
8
throwRenamedFunctionError ,
@@ -15,6 +13,7 @@ import {
15
13
getAllByPlaceholderText ,
16
14
getByPlaceholderText ,
17
15
} from './byPlaceholderText' ;
16
+ import { getAllByDisplayValue , getByDisplayValue } from './byDisplayValue' ;
18
17
19
18
export type GetByAPI = { |
20
19
getByText : ( text : string | RegExp ) => ReactTestInstance ,
@@ -47,54 +46,6 @@ export type GetByAPI = {|
47
46
getAllByPlaceholder : ( ) => void ,
48
47
| } ;
49
48
50
- const getTextInputNodeByDisplayValue = ( node , value ) => {
51
- try {
52
- const { TextInput } = require ( 'react-native' ) ;
53
- const nodeValue =
54
- node . props . value !== undefined
55
- ? node . props . value
56
- : node . props . defaultValue ;
57
- return (
58
- filterNodeByType ( node , TextInput ) &&
59
- ( typeof value === 'string' ? value === nodeValue : value . test ( nodeValue ) )
60
- ) ;
61
- } catch ( error ) {
62
- throw createLibraryNotSupportedError ( error ) ;
63
- }
64
- } ;
65
-
66
- export const getByDisplayValue = (
67
- instance: ReactTestInstance
68
- ): ((displayValue: string | RegExp) => ReactTestInstance ) =>
69
- function getByDisplayValueFn ( displayValue : string | RegExp ) {
70
- try {
71
- return instance . find ( ( node ) =>
72
- getTextInputNodeByDisplayValue ( node , displayValue )
73
- ) ;
74
- } catch ( error ) {
75
- throw new ErrorWithStack (
76
- prepareErrorMessage ( error , 'display value' , displayValue ) ,
77
- getByDisplayValueFn
78
- ) ;
79
- }
80
- } ;
81
-
82
- export const getAllByDisplayValue = (
83
- instance: ReactTestInstance
84
- ): ((value: string | RegExp) => Array < ReactTestInstance > ) =>
85
- function getAllByDisplayValueFn ( value : string | RegExp ) {
86
- const results = instance . findAll ( ( node ) =>
87
- getTextInputNodeByDisplayValue ( node , value )
88
- ) ;
89
- if ( results . length === 0 ) {
90
- throw new ErrorWithStack (
91
- `No instances found with display value: ${ String ( value ) } ` ,
92
- getAllByDisplayValueFn
93
- ) ;
94
- }
95
- return results ;
96
- } ;
97
-
98
49
export const UNSAFE_getByType = (
99
50
instance : ReactTestInstance
100
51
) : ( ( type : React . ComponentType < any > ) => ReactTestInstance ) =>
0 commit comments