mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
fix: Flow types (#16)
- [x] - Add flow to tests - [x] - Fix flow typings - [x] - Update documentation
This commit is contained in:
committed by
Michał Pierzchała
parent
d2e00f5264
commit
4f0501e6b5
@@ -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.
|
||||
|
||||
|
||||
Vendored
+1146
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,4 @@
|
||||
// @flow
|
||||
import React from 'react';
|
||||
import {
|
||||
View,
|
||||
|
||||
@@ -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
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user