|
1 | | -import React, {ComponentProps} from 'react'; |
2 | | -import {View, Text} from 'react-native'; |
3 | | -import {render, act} from '@testing-library/react-native'; |
| 1 | +import React, {ComponentProps, ForwardedRef, forwardRef} from 'react'; |
| 2 | +import {Text, TextInput, TextInputProps, View} from 'react-native'; |
| 3 | +import {act, render} from '@testing-library/react-native'; |
4 | 4 | import {CodeField} from '../CodeField'; |
5 | 5 | import {styles} from '../CodeField.styles'; |
6 | 6 |
|
@@ -82,3 +82,72 @@ it('should invoke renderCell for third cell when isFocused and it empty', () => |
82 | 82 | [{index: 3, isFocused: false, symbol: ''}], |
83 | 83 | ]); |
84 | 84 | }); |
| 85 | + |
| 86 | +{ |
| 87 | + console.log( |
| 88 | + <CodeField |
| 89 | + renderCell={() => null} |
| 90 | + ref={(ref: TextInput | null) => { |
| 91 | + ref?.focus(); |
| 92 | + ref?.blur(); |
| 93 | + }} |
| 94 | + />, |
| 95 | + ); |
| 96 | + |
| 97 | + console.log( |
| 98 | + // @ts-expect-error - number is not function |
| 99 | + <CodeField |
| 100 | + onChangeText={123} |
| 101 | + renderCell={() => null} |
| 102 | + ref={(ref: TextInput | null) => { |
| 103 | + ref?.focus(); |
| 104 | + ref?.blur(); |
| 105 | + }} |
| 106 | + />, |
| 107 | + ); |
| 108 | +} |
| 109 | + |
| 110 | +{ |
| 111 | + interface MyTextInput extends TextInputProps { |
| 112 | + myRequiredProps: string; |
| 113 | + } |
| 114 | + |
| 115 | + // eslint-disable-next-line react/display-name |
| 116 | + const MyTextInput = forwardRef( |
| 117 | + (props: MyTextInput, ref: ForwardedRef<TextInput>) => ( |
| 118 | + <View testID={props.myRequiredProps}> |
| 119 | + <TextInput ref={ref} /> |
| 120 | + </View> |
| 121 | + ), |
| 122 | + ); |
| 123 | + |
| 124 | + console.log( |
| 125 | + <CodeField |
| 126 | + renderCell={() => null} |
| 127 | + myRequiredProps="my-required-props" |
| 128 | + InputComponent={MyTextInput} |
| 129 | + />, |
| 130 | + ); |
| 131 | + |
| 132 | + console.log( |
| 133 | + // @ts-expect-error - `myRequiredProps` is required prop |
| 134 | + <CodeField<typeof MyTextInput> |
| 135 | + renderCell={() => null} |
| 136 | + InputComponent={MyTextInput} |
| 137 | + />, |
| 138 | + ); |
| 139 | + |
| 140 | + console.log( |
| 141 | + // @ts-expect-error - `myRequiredProps` is required prop |
| 142 | + <CodeField renderCell={() => null} InputComponent={MyTextInput} />, |
| 143 | + ); |
| 144 | + |
| 145 | + console.log( |
| 146 | + <CodeField |
| 147 | + renderCell={() => null} |
| 148 | + // @ts-expect-error - number is not string |
| 149 | + myRequiredProps={1} |
| 150 | + InputComponent={MyTextInput} |
| 151 | + />, |
| 152 | + ); |
| 153 | +} |
0 commit comments