Skip to content

Commit c5910d9

Browse files
authored
fix: remove deprecated existential Flow type and use any for now (#77)
<!-- Please provide enough information so that others can review your pull request. --> <!-- Keep pull requests small and focused on a single change. --> ### Summary Existential type (`*`) is long deprecated, let's just use `any` for now. ### Test plan Added some more Flow typings to `shallow.test.js` that were failing because of existential type.
1 parent 6dfbc67 commit c5910d9

File tree

7 files changed

+23
-14
lines changed

7 files changed

+23
-14
lines changed

docs/api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ Defined as:
88

99
```jsx
1010
function render(
11-
component: React.Element<*>,
11+
component: React.Element<any>,
1212
options?: {
1313
/* You won't often use this, but it's helpful when testing refs */
14-
createNodeMock: (element: React.Element<*>) => any,
14+
createNodeMock: (element: React.Element<any>) => any,
1515
}
1616
): RenderResult {}
1717
```
@@ -81,7 +81,7 @@ A method returning an array of `ReactTestInstance`s with matching a React compon
8181

8282
> This method has been **deprecated** because using it results in fragile tests that may break between minor React Native versions. It will be removed in next major release (v2.0). Use [`getAllByType`](#getallbytype-type-reactcomponenttype) instead.
8383
84-
### `update: (element: React.Element<*>) => void`
84+
### `update: (element: React.Element<any>) => void`
8585

8686
Re-render the in-memory tree with a new root element. This simulates a React update at the root. If the new element has the same type and key as the previous element, the tree will be updated; otherwise, it will re-mount a new tree.
8787

src/__tests__/__snapshots__/shallow.test.js.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ exports[`shallow rendering React Test Instance 1`] = `
1313
`;
1414

1515
exports[`shallow rendering React elements 1`] = `
16-
<View>
16+
<View
17+
testID="2"
18+
>
1719
<Text
1820
testID="text-button"
1921
>

src/__tests__/shallow.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ import React from 'react';
33
import { View, Text } from 'react-native';
44
import { shallow, render } from '..';
55

6-
const TextPress = () => (
7-
<View>
6+
type Props = {|
7+
+dummyID?: string,
8+
|};
9+
10+
const TextPress = ({ dummyID }: Props) => (
11+
<View testID={dummyID}>
812
<Text testID="text-button">Press me</Text>
913
</View>
1014
);
1115

1216
test('shallow rendering React elements', () => {
13-
const { output } = shallow(<TextPress />);
17+
const { output } = shallow(<TextPress dummyID="2" />);
1418

1519
expect(output).toMatchSnapshot();
1620
});

src/debug.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import format from './helpers/format';
1010
* Log pretty-printed deep test component instance
1111
*/
1212
function debugDeepElementOrInstance(
13-
instance: React.Element<*> | ?ReactTestRendererJSON,
13+
instance: React.Element<any> | ?ReactTestRendererJSON,
1414
message?: any = ''
1515
) {
1616
try {
17-
// We're assuming React.Element<*> here and fallback to
17+
// We're assuming React.Element<any> here and fallback to
1818
// rendering ?ReactTestRendererJSON
1919
// $FlowFixMe
2020
const { toJSON } = render(instance);
@@ -29,7 +29,10 @@ function debugDeepElementOrInstance(
2929
}
3030
}
3131

32-
function debug(instance: ReactTestInstance | React.Element<*>, message?: any) {
32+
function debug(
33+
instance: ReactTestInstance | React.Element<any>,
34+
message?: any
35+
) {
3336
return debugShallow(instance, message);
3437
}
3538

src/helpers/debugShallow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import format from './format';
77
* Log pretty-printed shallow test component instance
88
*/
99
export default function debugShallow(
10-
instance: ReactTestInstance | React.Element<*>,
10+
instance: ReactTestInstance | React.Element<any>,
1111
message?: any
1212
) {
1313
const { output } = shallow(instance);

src/render.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import debugDeep from './helpers/debugDeep';
1111
* to assert on the output.
1212
*/
1313
export default function render(
14-
component: React.Element<*>,
15-
options?: { createNodeMock: (element: React.Element<*>) => any }
14+
component: React.Element<any>,
15+
options?: { createNodeMock: (element: React.Element<any>) => any }
1616
) {
1717
const renderer = TestRenderer.create(component, options);
1818
const instance = renderer.root;

src/shallow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ShallowRenderer from 'react-test-renderer/shallow'; // eslint-disable-lin
66
* Renders test component shallowly using react-test-renderer/shallow
77
*/
88
export default function shallow(
9-
instance: ReactTestInstance | React.Element<*>
9+
instance: ReactTestInstance | React.Element<any>
1010
) {
1111
const renderer = new ShallowRenderer();
1212

0 commit comments

Comments
 (0)