diff --git a/src/__tests__/fireEvent.test.tsx b/src/__tests__/fireEvent.test.tsx
index 184ba6067..ce6266dfe 100644
--- a/src/__tests__/fireEvent.test.tsx
+++ b/src/__tests__/fireEvent.test.tsx
@@ -217,25 +217,6 @@ test('should not fire on disabled Pressable', () => {
});
test('should not fire on non-editable TextInput', () => {
- const placeholder = 'Test placeholder';
- const onChangeTextMock = jest.fn();
- const NEW_TEXT = 'New text';
-
- const { getByPlaceholderText } = render(
-
-
-
- );
-
- fireEvent.changeText(getByPlaceholderText(placeholder), NEW_TEXT);
- expect(onChangeTextMock).not.toHaveBeenCalled();
-});
-
-test('should not fire on non-editable host TextInput', () => {
const testID = 'my-text-input';
const onChangeTextMock = jest.fn();
const NEW_TEXT = 'New text';
@@ -245,7 +226,6 @@ test('should not fire on non-editable host TextInput', () => {
editable={false}
testID={testID}
onChangeText={onChangeTextMock}
- placeholder="placeholder"
/>
);
diff --git a/src/__tests__/react-native-api.test.tsx b/src/__tests__/react-native-api.test.tsx
index 2bf699f3a..0a1383dab 100644
--- a/src/__tests__/react-native-api.test.tsx
+++ b/src/__tests__/react-native-api.test.tsx
@@ -1,7 +1,6 @@
import * as React from 'react';
import { View, Text, TextInput } from 'react-native';
import { render } from '..';
-import { getHostSelf } from '../helpers/component-tree';
/**
* Tests in this file are intended to give us an proactive warning that React Native behavior has
@@ -10,8 +9,6 @@ import { getHostSelf } from '../helpers/component-tree';
test('React Native API assumption: renders single host element', () => {
const view = render();
- const hostView = view.getByTestId('test');
- expect(getHostSelf(hostView)).toBe(hostView);
expect(view.toJSON()).toMatchInlineSnapshot(`
renders single host element', () => {
test('React Native API assumption: renders single host element', () => {
const view = render(Hello);
- const compositeView = view.getByText('Hello');
- const hostView = view.getByTestId('test');
- expect(getHostSelf(compositeView)).toBe(hostView);
+ expect(view.getByText('Hello')).toBe(view.getByTestId('test'));
expect(view.toJSON()).toMatchInlineSnapshot(`
renders single host element', (
);
- expect(getHostSelf(view.getByText(/Hello/))).toBe(view.getByTestId('test'));
- expect(getHostSelf(view.getByText('Before'))).toBe(
- view.getByTestId('before')
- );
- expect(getHostSelf(view.getByText('Deeply nested'))).toBe(
+ expect(view.getByText(/Hello/)).toBe(view.getByTestId('test'));
+ expect(view.getByText('Before')).toBe(view.getByTestId('before'));
+ expect(view.getByText('Deeply nested')).toBe(
view.getByTestId('deeplyNested')
);
@@ -85,9 +78,9 @@ test('React Native API assumption: renders single host element', ()
placeholder="Placeholder"
/>
);
- const compositeView = view.getByPlaceholderText('Placeholder');
- const hostView = view.getByTestId('test');
- expect(getHostSelf(compositeView)).toBe(hostView);
+ expect(view.getByPlaceholderText('Placeholder')).toBe(
+ view.getByTestId('test')
+ );
expect(view.toJSON()).toMatchInlineSnapshot(`
{
test('getQueriesForElement is alias to within', () => {
expect(getQueriesForElement).toBe(within);
});
-
-test('within allows searching for text within a composite component', () => {
- const view = render(Hello);
- // view.getByTestId('subject') returns a host component, contrary to text queries returning a composite component
- // we want to be sure that this doesn't interfere with the way text is searched
- const hostTextQueries = within(view.getByTestId('subject'));
- expect(hostTextQueries.getByText('Hello')).toBeTruthy();
-});
diff --git a/src/fireEvent.ts b/src/fireEvent.ts
index c4e451dc3..e60398bc1 100644
--- a/src/fireEvent.ts
+++ b/src/fireEvent.ts
@@ -12,11 +12,10 @@ const isTextInput = (element?: ReactTestInstance) => {
return false;
}
- // We have to test if the element type is either the TextInput component
- // (which would if it is a composite component) or the string
- // TextInput (which would be true if it is a host component)
+ // We have to test if the element type is either the `TextInput` component
+ // (for composite component) or the string "TextInput" (for host component)
// All queries return host components but since fireEvent bubbles up
- // it would trigger the parent prop without the composite component check
+ // it would trigger the parent prop without the composite component check.
return (
filterNodeByType(element, TextInput) ||
filterNodeByType(element, getHostComponentNames().textInput)
diff --git a/src/helpers/__tests__/component-tree.test.tsx b/src/helpers/__tests__/component-tree.test.tsx
index 39ce7252b..869a76131 100644
--- a/src/helpers/__tests__/component-tree.test.tsx
+++ b/src/helpers/__tests__/component-tree.test.tsx
@@ -142,17 +142,13 @@ describe('getHostSelf()', () => {
);
- const compositeText = view.getByText('Text');
+ const compositeText = view.UNSAFE_getByType(Text);
const hostText = view.getByTestId('text');
expect(getHostSelf(compositeText)).toEqual(hostText);
- const compositeTextInputByValue = view.getByDisplayValue('TextInputValue');
- const compositeTextInputByPlaceholder = view.getByPlaceholderText(
- 'TextInputPlaceholder'
- );
+ const compositeTextInput = view.UNSAFE_getByType(TextInput);
const hostTextInput = view.getByTestId('textInput');
- expect(getHostSelf(compositeTextInputByValue)).toEqual(hostTextInput);
- expect(getHostSelf(compositeTextInputByPlaceholder)).toEqual(hostTextInput);
+ expect(getHostSelf(compositeTextInput)).toEqual(hostTextInput);
});
it('throws on non-single host children elements for custom composite components', () => {