Skip to content

Commit 78194d1

Browse files
refactor: remove stale tests (#1392)
1 parent 4ac2833 commit 78194d1

File tree

5 files changed

+13
-53
lines changed

5 files changed

+13
-53
lines changed

src/__tests__/fireEvent.test.tsx

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -217,25 +217,6 @@ test('should not fire on disabled Pressable', () => {
217217
});
218218

219219
test('should not fire on non-editable TextInput', () => {
220-
const placeholder = 'Test placeholder';
221-
const onChangeTextMock = jest.fn();
222-
const NEW_TEXT = 'New text';
223-
224-
const { getByPlaceholderText } = render(
225-
<View>
226-
<TextInput
227-
editable={false}
228-
placeholder={placeholder}
229-
onChangeText={onChangeTextMock}
230-
/>
231-
</View>
232-
);
233-
234-
fireEvent.changeText(getByPlaceholderText(placeholder), NEW_TEXT);
235-
expect(onChangeTextMock).not.toHaveBeenCalled();
236-
});
237-
238-
test('should not fire on non-editable host TextInput', () => {
239220
const testID = 'my-text-input';
240221
const onChangeTextMock = jest.fn();
241222
const NEW_TEXT = 'New text';
@@ -245,7 +226,6 @@ test('should not fire on non-editable host TextInput', () => {
245226
editable={false}
246227
testID={testID}
247228
onChangeText={onChangeTextMock}
248-
placeholder="placeholder"
249229
/>
250230
);
251231

src/__tests__/react-native-api.test.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as React from 'react';
22
import { View, Text, TextInput } from 'react-native';
33
import { render } from '..';
4-
import { getHostSelf } from '../helpers/component-tree';
54

65
/**
76
* 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';
109

1110
test('React Native API assumption: <View> renders single host element', () => {
1211
const view = render(<View testID="test" />);
13-
const hostView = view.getByTestId('test');
14-
expect(getHostSelf(hostView)).toBe(hostView);
1512

1613
expect(view.toJSON()).toMatchInlineSnapshot(`
1714
<View
@@ -22,9 +19,7 @@ test('React Native API assumption: <View> renders single host element', () => {
2219

2320
test('React Native API assumption: <Text> renders single host element', () => {
2421
const view = render(<Text testID="test">Hello</Text>);
25-
const compositeView = view.getByText('Hello');
26-
const hostView = view.getByTestId('test');
27-
expect(getHostSelf(compositeView)).toBe(hostView);
22+
expect(view.getByText('Hello')).toBe(view.getByTestId('test'));
2823

2924
expect(view.toJSON()).toMatchInlineSnapshot(`
3025
<Text
@@ -45,11 +40,9 @@ test('React Native API assumption: nested <Text> renders single host element', (
4540
</Text>
4641
</Text>
4742
);
48-
expect(getHostSelf(view.getByText(/Hello/))).toBe(view.getByTestId('test'));
49-
expect(getHostSelf(view.getByText('Before'))).toBe(
50-
view.getByTestId('before')
51-
);
52-
expect(getHostSelf(view.getByText('Deeply nested'))).toBe(
43+
expect(view.getByText(/Hello/)).toBe(view.getByTestId('test'));
44+
expect(view.getByText('Before')).toBe(view.getByTestId('before'));
45+
expect(view.getByText('Deeply nested')).toBe(
5346
view.getByTestId('deeplyNested')
5447
);
5548

@@ -85,9 +78,9 @@ test('React Native API assumption: <TextInput> renders single host element', ()
8578
placeholder="Placeholder"
8679
/>
8780
);
88-
const compositeView = view.getByPlaceholderText('Placeholder');
89-
const hostView = view.getByTestId('test');
90-
expect(getHostSelf(compositeView)).toBe(hostView);
81+
expect(view.getByPlaceholderText('Placeholder')).toBe(
82+
view.getByTestId('test')
83+
);
9184

9285
expect(view.toJSON()).toMatchInlineSnapshot(`
9386
<TextInput

src/__tests__/within.test.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,3 @@ test('within() exposes a11y queries', async () => {
9494
test('getQueriesForElement is alias to within', () => {
9595
expect(getQueriesForElement).toBe(within);
9696
});
97-
98-
test('within allows searching for text within a composite component', () => {
99-
const view = render(<Text testID="subject">Hello</Text>);
100-
// view.getByTestId('subject') returns a host component, contrary to text queries returning a composite component
101-
// we want to be sure that this doesn't interfere with the way text is searched
102-
const hostTextQueries = within(view.getByTestId('subject'));
103-
expect(hostTextQueries.getByText('Hello')).toBeTruthy();
104-
});

src/fireEvent.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ const isTextInput = (element?: ReactTestInstance) => {
1212
return false;
1313
}
1414

15-
// We have to test if the element type is either the TextInput component
16-
// (which would if it is a composite component) or the string
17-
// TextInput (which would be true if it is a host component)
15+
// We have to test if the element type is either the `TextInput` component
16+
// (for composite component) or the string "TextInput" (for host component)
1817
// All queries return host components but since fireEvent bubbles up
19-
// it would trigger the parent prop without the composite component check
18+
// it would trigger the parent prop without the composite component check.
2019
return (
2120
filterNodeByType(element, TextInput) ||
2221
filterNodeByType(element, getHostComponentNames().textInput)

src/helpers/__tests__/component-tree.test.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,13 @@ describe('getHostSelf()', () => {
142142
</View>
143143
);
144144

145-
const compositeText = view.getByText('Text');
145+
const compositeText = view.UNSAFE_getByType(Text);
146146
const hostText = view.getByTestId('text');
147147
expect(getHostSelf(compositeText)).toEqual(hostText);
148148

149-
const compositeTextInputByValue = view.getByDisplayValue('TextInputValue');
150-
const compositeTextInputByPlaceholder = view.getByPlaceholderText(
151-
'TextInputPlaceholder'
152-
);
149+
const compositeTextInput = view.UNSAFE_getByType(TextInput);
153150
const hostTextInput = view.getByTestId('textInput');
154-
expect(getHostSelf(compositeTextInputByValue)).toEqual(hostTextInput);
155-
expect(getHostSelf(compositeTextInputByPlaceholder)).toEqual(hostTextInput);
151+
expect(getHostSelf(compositeTextInput)).toEqual(hostTextInput);
156152
});
157153

158154
it('throws on non-single host children elements for custom composite components', () => {

0 commit comments

Comments
 (0)