Skip to content

Commit d030a18

Browse files
committed
refactor: cleanup react native api assumptions
1 parent 0c9c10e commit d030a18

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { View, Text, TextInput } from 'react-native';
2+
import { View, Text, TextInput, Switch } from 'react-native';
33
import { render } from '..';
44

55
/**
@@ -19,7 +19,6 @@ test('React Native API assumption: <View> renders single host element', () => {
1919

2020
test('React Native API assumption: <Text> renders single host element', () => {
2121
const view = render(<Text testID="test">Hello</Text>);
22-
expect(view.getByText('Hello')).toBe(view.getByTestId('test'));
2322

2423
expect(view.toJSON()).toMatchInlineSnapshot(`
2524
<Text
@@ -40,11 +39,6 @@ test('React Native API assumption: nested <Text> renders single host element', (
4039
</Text>
4140
</Text>
4241
);
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(
46-
view.getByTestId('deeplyNested')
47-
);
4842

4943
expect(view.toJSON()).toMatchInlineSnapshot(`
5044
<Text
@@ -78,10 +72,6 @@ test('React Native API assumption: <TextInput> renders single host element', ()
7872
placeholder="Placeholder"
7973
/>
8074
);
81-
expect(view.getByPlaceholderText('Placeholder')).toBe(
82-
view.getByTestId('test')
83-
);
84-
8575
expect(view.toJSON()).toMatchInlineSnapshot(`
8676
<TextInput
8777
defaultValue="default"
@@ -91,3 +81,27 @@ test('React Native API assumption: <TextInput> renders single host element', ()
9181
/>
9282
`);
9383
});
84+
85+
test('React Native API assumption: <Switch> renders single host element', () => {
86+
const view = render(
87+
<Switch testID="test" value={true} onChange={jest.fn()} />
88+
);
89+
expect(view.getByTestId('test')).toBe(view.getByTestId('test'));
90+
91+
expect(view.toJSON()).toMatchInlineSnapshot(`
92+
<RCTSwitch
93+
accessibilityRole="switch"
94+
onChange={[Function]}
95+
onResponderTerminationRequest={[Function]}
96+
onStartShouldSetResponder={[Function]}
97+
style={
98+
{
99+
"height": 31,
100+
"width": 51,
101+
}
102+
}
103+
testID="test"
104+
value={true}
105+
/>
106+
`);
107+
});

0 commit comments

Comments
 (0)