Skip to content

fix: remove deprecated existential Flow type and use any for now #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Defined as:

```jsx
function render(
component: React.Element<*>,
component: React.Element<any>,
options?: {
/* You won't often use this, but it's helpful when testing refs */
createNodeMock: (element: React.Element<*>) => any,
createNodeMock: (element: React.Element<any>) => any,
}
): RenderResult {}
```
Expand Down Expand Up @@ -77,7 +77,7 @@ A method returning an array of `ReactTestInstance`s with matching a React compon

> 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.

### `update: (element: React.Element<*>) => void`
### `update: (element: React.Element<any>) => void`

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.

Expand Down
4 changes: 3 additions & 1 deletion src/__tests__/__snapshots__/shallow.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ exports[`shallow rendering React Test Instance 1`] = `
`;

exports[`shallow rendering React elements 1`] = `
<View>
<View
testID="2"
>
<Text
testID="text-button"
>
Expand Down
10 changes: 7 additions & 3 deletions src/__tests__/shallow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import React from 'react';
import { View, Text } from 'react-native';
import { shallow, render } from '..';

const TextPress = () => (
<View>
type Props = {|
+dummyID?: string,
|};

const TextPress = ({ dummyID }: Props) => (
<View testID={dummyID}>
<Text testID="text-button">Press me</Text>
</View>
);

test('shallow rendering React elements', () => {
const { output } = shallow(<TextPress />);
const { output } = shallow(<TextPress dummyID="2" />);

expect(output).toMatchSnapshot();
});
Expand Down
9 changes: 6 additions & 3 deletions src/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import format from './helpers/format';
* Log pretty-printed deep test component instance
*/
function debugDeepElementOrInstance(
instance: React.Element<*> | ?ReactTestRendererJSON,
instance: React.Element<any> | ?ReactTestRendererJSON,
message?: any = ''
) {
try {
// We're assuming React.Element<*> here and fallback to
// We're assuming React.Element<any> here and fallback to
// rendering ?ReactTestRendererJSON
// $FlowFixMe
const { toJSON } = render(instance);
Expand All @@ -29,7 +29,10 @@ function debugDeepElementOrInstance(
}
}

function debug(instance: ReactTestInstance | React.Element<*>, message?: any) {
function debug(
instance: ReactTestInstance | React.Element<any>,
message?: any
) {
return debugShallow(instance, message);
}

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/debugShallow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import format from './format';
* Log pretty-printed shallow test component instance
*/
export default function debugShallow(
instance: ReactTestInstance | React.Element<*>,
instance: ReactTestInstance | React.Element<any>,
message?: any
) {
const { output } = shallow(instance);
Expand Down
4 changes: 2 additions & 2 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import debugDeep from './helpers/debugDeep';
* to assert on the output.
*/
export default function render(
component: React.Element<*>,
options?: { createNodeMock: (element: React.Element<*>) => any }
component: React.Element<any>,
options?: { createNodeMock: (element: React.Element<any>) => any }
) {
const renderer = TestRenderer.create(component, options);
const instance = renderer.root;
Expand Down
2 changes: 1 addition & 1 deletion src/shallow.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ShallowRenderer from 'react-test-renderer/shallow'; // eslint-disable-lin
* Renders test component shallowly using react-test-renderer/shallow
*/
export default function shallow(
instance: ReactTestInstance | React.Element<*>
instance: ReactTestInstance | React.Element<any>
) {
const renderer = new ShallowRenderer();

Expand Down