From c5910d94e4f7246d6e67c1374300408a71ca7e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Wed, 28 Nov 2018 12:49:15 +0100 Subject: [PATCH] fix: remove deprecated existential Flow type and use any for now (#77) ### 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. --- docs/api.md | 6 +++--- src/__tests__/__snapshots__/shallow.test.js.snap | 4 +++- src/__tests__/shallow.test.js | 10 +++++++--- src/debug.js | 9 ++++++--- src/helpers/debugShallow.js | 2 +- src/render.js | 4 ++-- src/shallow.js | 2 +- 7 files changed, 23 insertions(+), 14 deletions(-) diff --git a/docs/api.md b/docs/api.md index b2db07e3..e94e8d24 100644 --- a/docs/api.md +++ b/docs/api.md @@ -8,10 +8,10 @@ Defined as: ```jsx function render( - component: React.Element<*>, + component: React.Element, options?: { /* You won't often use this, but it's helpful when testing refs */ - createNodeMock: (element: React.Element<*>) => any, + createNodeMock: (element: React.Element) => any, } ): RenderResult {} ``` @@ -81,7 +81,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) => 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. diff --git a/src/__tests__/__snapshots__/shallow.test.js.snap b/src/__tests__/__snapshots__/shallow.test.js.snap index ec845ddc..37c0b834 100644 --- a/src/__tests__/__snapshots__/shallow.test.js.snap +++ b/src/__tests__/__snapshots__/shallow.test.js.snap @@ -13,7 +13,9 @@ exports[`shallow rendering React Test Instance 1`] = ` `; exports[`shallow rendering React elements 1`] = ` - + diff --git a/src/__tests__/shallow.test.js b/src/__tests__/shallow.test.js index a806518f..927ee1bf 100644 --- a/src/__tests__/shallow.test.js +++ b/src/__tests__/shallow.test.js @@ -3,14 +3,18 @@ import React from 'react'; import { View, Text } from 'react-native'; import { shallow, render } from '..'; -const TextPress = () => ( - +type Props = {| + +dummyID?: string, +|}; + +const TextPress = ({ dummyID }: Props) => ( + Press me ); test('shallow rendering React elements', () => { - const { output } = shallow(); + const { output } = shallow(); expect(output).toMatchSnapshot(); }); diff --git a/src/debug.js b/src/debug.js index 0cd63a10..807eaa57 100644 --- a/src/debug.js +++ b/src/debug.js @@ -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 | ?ReactTestRendererJSON, message?: any = '' ) { try { - // We're assuming React.Element<*> here and fallback to + // We're assuming React.Element here and fallback to // rendering ?ReactTestRendererJSON // $FlowFixMe const { toJSON } = render(instance); @@ -29,7 +29,10 @@ function debugDeepElementOrInstance( } } -function debug(instance: ReactTestInstance | React.Element<*>, message?: any) { +function debug( + instance: ReactTestInstance | React.Element, + message?: any +) { return debugShallow(instance, message); } diff --git a/src/helpers/debugShallow.js b/src/helpers/debugShallow.js index 1df22436..896e059d 100644 --- a/src/helpers/debugShallow.js +++ b/src/helpers/debugShallow.js @@ -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, message?: any ) { const { output } = shallow(instance); diff --git a/src/render.js b/src/render.js index a953e90e..3262645e 100644 --- a/src/render.js +++ b/src/render.js @@ -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, + options?: { createNodeMock: (element: React.Element) => any } ) { const renderer = TestRenderer.create(component, options); const instance = renderer.root; diff --git a/src/shallow.js b/src/shallow.js index 65509330..e07b123c 100644 --- a/src/shallow.js +++ b/src/shallow.js @@ -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 ) { const renderer = new ShallowRenderer();