mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
TextInput-test: use act-wrapping abstraction for create
Summary: Migrate TextInput-test to act-wrapping abstractions for `react-test-renderer` `create`, in preparation for React 19. Changelog: [Internal] Reviewed By: yungsters Differential Revision: D58653346 fbshipit-source-id: 3fe191cbb274b651e98e75c0059011943755a5bc
This commit is contained in:
committed by
Facebook GitHub Bot
parent
53c125ee6e
commit
9af481d38b
+21
-20
@@ -7,6 +7,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
const {create} = require('../../../../jest/renderer');
|
||||
const ReactNative = require('../../../ReactNative/RendererProxy');
|
||||
const {
|
||||
enter,
|
||||
@@ -24,7 +25,7 @@ describe('TextInput tests', () => {
|
||||
let onChangeListener;
|
||||
let onChangeTextListener;
|
||||
const initialValue = 'initialValue';
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
inputRef = React.createRef(null);
|
||||
onChangeListener = jest.fn();
|
||||
onChangeTextListener = jest.fn();
|
||||
@@ -45,7 +46,7 @@ describe('TextInput tests', () => {
|
||||
/>
|
||||
);
|
||||
}
|
||||
const renderTree = ReactTestRenderer.create(<TextInputWrapper />);
|
||||
const renderTree = await create(<TextInputWrapper />);
|
||||
input = renderTree.root.findByType(TextInput);
|
||||
});
|
||||
it('has expected instance functions', () => {
|
||||
@@ -77,16 +78,16 @@ describe('TextInput tests', () => {
|
||||
});
|
||||
});
|
||||
|
||||
function createTextInput(extraProps) {
|
||||
async function createTextInput(extraProps) {
|
||||
const textInputRef = React.createRef(null);
|
||||
ReactTestRenderer.create(
|
||||
await create(
|
||||
<TextInput ref={textInputRef} value="value1" {...extraProps} />,
|
||||
);
|
||||
return textInputRef;
|
||||
}
|
||||
|
||||
it('focus() should not do anything if the TextInput is not editable', () => {
|
||||
const textInputRef = createTextInput({editable: false});
|
||||
it('focus() should not do anything if the TextInput is not editable', async () => {
|
||||
const textInputRef = await createTextInput({editable: false});
|
||||
textInputRef.current.currentProps = textInputRef.current.props;
|
||||
expect(textInputRef.current.isFocused()).toBe(false);
|
||||
|
||||
@@ -94,8 +95,8 @@ describe('TextInput tests', () => {
|
||||
expect(textInputRef.current.isFocused()).toBe(false);
|
||||
});
|
||||
|
||||
it('should have support for being focused and blurred', () => {
|
||||
const textInputRef = createTextInput();
|
||||
it('should have support for being focused and blurred', async () => {
|
||||
const textInputRef = await createTextInput();
|
||||
|
||||
expect(textInputRef.current.isFocused()).toBe(false);
|
||||
ReactNative.findNodeHandle = jest.fn().mockImplementation(ref => {
|
||||
@@ -122,11 +123,11 @@ describe('TextInput tests', () => {
|
||||
expect(TextInput.State.currentlyFocusedInput()).toBe(null);
|
||||
});
|
||||
|
||||
it('should unfocus when other TextInput is focused', () => {
|
||||
it('should unfocus when other TextInput is focused', async () => {
|
||||
const textInputRe1 = React.createRef(null);
|
||||
const textInputRe2 = React.createRef(null);
|
||||
|
||||
ReactTestRenderer.create(
|
||||
await create(
|
||||
<>
|
||||
<TextInput ref={textInputRe1} value="value1" />
|
||||
<TextInput ref={textInputRe2} value="value2" />
|
||||
@@ -166,8 +167,8 @@ describe('TextInput tests', () => {
|
||||
expect(TextInput.State.currentlyFocusedInput()).toBe(textInputRe2.current);
|
||||
});
|
||||
|
||||
it('should give precedence to `textContentType` when set', () => {
|
||||
const instance = ReactTestRenderer.create(
|
||||
it('should give precedence to `textContentType` when set', async () => {
|
||||
const instance = await create(
|
||||
<TextInput autoComplete="tel" textContentType="emailAddress" />,
|
||||
);
|
||||
|
||||
@@ -213,8 +214,8 @@ describe('TextInput tests', () => {
|
||||
});
|
||||
|
||||
describe('TextInput', () => {
|
||||
it('default render', () => {
|
||||
const instance = ReactTestRenderer.create(<TextInput />);
|
||||
it('default render', async () => {
|
||||
const instance = await create(<TextInput />);
|
||||
|
||||
expect(instance.toJSON()).toMatchInlineSnapshot(`
|
||||
<RCTSinglelineTextInputView
|
||||
@@ -251,14 +252,14 @@ describe('TextInput', () => {
|
||||
});
|
||||
|
||||
describe('TextInput compat with web', () => {
|
||||
it('renders core props', () => {
|
||||
it('renders core props', async () => {
|
||||
const props = {
|
||||
id: 'id',
|
||||
tabIndex: 0,
|
||||
testID: 'testID',
|
||||
};
|
||||
|
||||
const instance = ReactTestRenderer.create(<TextInput {...props} />);
|
||||
const instance = await create(<TextInput {...props} />);
|
||||
|
||||
expect(instance.toJSON()).toMatchInlineSnapshot(`
|
||||
<RCTSinglelineTextInputView
|
||||
@@ -291,7 +292,7 @@ describe('TextInput compat with web', () => {
|
||||
`);
|
||||
});
|
||||
|
||||
it('renders "aria-*" props', () => {
|
||||
it('renders "aria-*" props', async () => {
|
||||
const props = {
|
||||
'aria-activedescendant': 'activedescendant',
|
||||
'aria-atomic': true,
|
||||
@@ -341,7 +342,7 @@ describe('TextInput compat with web', () => {
|
||||
'aria-valuetext': '3',
|
||||
};
|
||||
|
||||
const instance = ReactTestRenderer.create(<TextInput {...props} />);
|
||||
const instance = await create(<TextInput {...props} />);
|
||||
|
||||
expect(instance.toJSON()).toMatchInlineSnapshot(`
|
||||
<RCTSinglelineTextInputView
|
||||
@@ -422,7 +423,7 @@ describe('TextInput compat with web', () => {
|
||||
`);
|
||||
});
|
||||
|
||||
it('renders styles', () => {
|
||||
it('renders styles', async () => {
|
||||
const style = {
|
||||
display: 'flex',
|
||||
flex: 1,
|
||||
@@ -432,7 +433,7 @@ describe('TextInput compat with web', () => {
|
||||
verticalAlign: 'middle',
|
||||
};
|
||||
|
||||
const instance = ReactTestRenderer.create(<TextInput style={style} />);
|
||||
const instance = await create(<TextInput style={style} />);
|
||||
|
||||
expect(instance.toJSON()).toMatchInlineSnapshot(`
|
||||
<RCTSinglelineTextInputView
|
||||
|
||||
Reference in New Issue
Block a user