fix: Flow types (#16)

- [x] - Add flow to tests
- [x] - Fix flow typings
- [x] - Update documentation
This commit is contained in:
Kacper Wiszczuk
2018-10-07 14:50:05 +02:00
committed by Michał Pierzchała
parent d2e00f5264
commit 4f0501e6b5
7 changed files with 1160 additions and 30 deletions
+2 -2
View File
@@ -102,11 +102,11 @@ type ReactTestInstance = {
};
```
### `getByName: (name: string | React.Element<*>)`
### `getByName: (name: string | React.ComponentType<*>)`
A method returning a `ReactTestInstance` with matching name – may be a string or React Element. Throws when no matches.
### `getAllByName: (name: string | React.Element<*>)`
### `getAllByName: (name: string | React.ComponentType<*>)`
A method returning an array of `ReactTestInstance`s with matching name – may be a string or React Element.
+1146
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -1,3 +1,4 @@
// @flow
import React from 'react';
import {
View,
+3 -2
View File
@@ -1,9 +1,10 @@
// @flow
/* eslint-disable react/no-multi-comp */
import React from 'react';
import { View, Text, TouchableOpacity } from '../__mocks__/reactNativeMock';
import { render } from '..';
class Button extends React.Component {
class Button extends React.Component<*> {
render() {
return (
<TouchableOpacity onPress={this.props.onPress}>
@@ -13,7 +14,7 @@ class Button extends React.Component {
}
}
class Banana extends React.Component {
class Banana extends React.Component<*, *> {
state = {
fresh: false,
};
+4 -22
View File
@@ -40,29 +40,11 @@ const changeTextHandler = (element: ReactTestInstance, data?: *) =>
const scrollHandler = (element: ReactTestInstance, data?: *) =>
invokeEvent(element, 'scroll', data);
const EVENTS = [
{
name: 'press',
handler: pressHandler,
},
{
name: 'doublePress',
handler: doublePressHandler,
},
{
name: 'changeText',
handler: changeTextHandler,
},
{
name: 'scroll',
handler: scrollHandler,
},
];
const fireEvent = invokeEvent;
EVENTS.forEach(event => {
fireEvent[event.name] = event.handler;
});
fireEvent.press = pressHandler;
fireEvent.doublePress = doublePressHandler;
fireEvent.changeText = changeTextHandler;
fireEvent.scroll = scrollHandler;
export default fireEvent;
+2 -2
View File
@@ -14,7 +14,7 @@ const getNodeByText = (node, text) =>
: text.test(node.props.children));
export const getByName = (instance: ReactTestInstance) => (
name: string | React.Element<*>
name: string | React.ComponentType<*>
) => {
try {
return instance.find(node => getNodeByName(node, name));
@@ -47,7 +47,7 @@ export const getByTestId = (instance: ReactTestInstance) => (testID: string) =>
getByProps(instance)({ testID });
export const getAllByName = (instance: ReactTestInstance) => (
name: string | React.Element<*>
name: string | React.ComponentType<*>
) => {
const results = instance.findAll(node => getNodeByName(node, name));
if (results.length === 0) {
+2 -2
View File
@@ -11,7 +11,7 @@ import {
} from './getByAPI';
export const queryByName = (instance: ReactTestInstance) => (
name: string | React.Element<*>
name: string | React.ComponentType<*>
) => {
try {
return getByName(instance)(name);
@@ -51,7 +51,7 @@ export const queryByTestId = (instance: ReactTestInstance) => (
};
export const queryAllByName = (instance: ReactTestInstance) => (
name: string | React.Element<*>
name: string | React.ComponentType<*>
) => {
try {
return getAllByName(instance)(name);