Skip to content

Commit ea125c9

Browse files
committed
Merge remote-tracking branch 'origin/master' into pr/74
* origin/master: chore: Update flow-bin to the latest version 🚀 (callstack#86) chore: Greenkeeper/@types/react 16.7.11 (callstack#82) chore: release 1.4.2 fix: add errors for queryBy* helpers when more instances found (callstack#79) chore: release 1.4.1 chore: release 1.4.1-es5.1 fix: remove deprecated existential Flow type and use any for now (callstack#77) docs: add note about new APIs in v1.4 (callstack#76) chore: Update flow-bin to the latest version 🚀 (callstack#75)
2 parents e3859a2 + 1673bc0 commit ea125c9

File tree

14 files changed

+146
-75
lines changed

14 files changed

+146
-75
lines changed

.flowconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ include_warnings=true
6969
.*/Libraries/YellowBox/UI/YellowBoxList.js
7070

7171
[version]
72-
^0.86.0
72+
^0.88.0

docs/api.md

Lines changed: 7 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
```
@@ -59,10 +59,14 @@ A method returning an array of `ReactTestInstance`s with matching props object.
5959

6060
### `getByType: (type: React.ComponentType<*>)`
6161

62+
> Note: added in v1.4
63+
6264
A method returning a `ReactTestInstance` with matching a React component type. Throws when no matches.
6365

6466
### `getAllByType: (type: React.ComponentType<*>)`
6567

68+
> Note: added in v1.4
69+
6670
A method returning an array of `ReactTestInstance`s with matching a React component type.
6771

6872
### `[DEPRECATED] getByName: (name: React.ComponentType<*>)`
@@ -77,7 +81,7 @@ A method returning an array of `ReactTestInstance`s with matching a React compon
7781

7882
> 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.
7983
80-
### `update: (element: React.Element<*>) => void`
84+
### `update: (element: React.Element<any>) => void`
8185

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

package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-testing-library",
3-
"version": "1.4.1-es5.0",
3+
"version": "1.4.2",
44
"description": "Simple React Native testing utilities helping you write better tests with less effort",
55
"main": "build/index.js",
66
"typings": "./typings/index.d.ts",
@@ -13,15 +13,15 @@
1313
"@babel/core": "^7.1.2",
1414
"@babel/runtime": "^7.1.2",
1515
"@callstack/eslint-config": "^3.0.0",
16-
"@types/react": "^16.4.15",
16+
"@types/react": "^16.7.11",
1717
"@types/react-test-renderer": "^16.0.3",
1818
"babel-core": "7.0.0-bridge.0",
1919
"babel-jest": "^23.6.0",
2020
"chalk": "^2.4.1",
2121
"conventional-changelog-cli": "^2.0.11",
2222
"dedent": "^0.7.0",
2323
"eslint": "^5.6.1",
24-
"flow-bin": "^0.86.0",
24+
"flow-bin": "^0.88.0",
2525
"flow-copy-source": "^2.0.2",
2626
"jest": "^23.6.0",
2727
"metro-react-native-babel-preset": "^0.49.0",
@@ -41,7 +41,7 @@
4141
},
4242
"scripts": {
4343
"test": "jest",
44-
"flow-check": "flow check",
44+
"flow-check": "flow check --ignore-version",
4545
"typescript-check": "tsc --noEmit --skipLibCheck --jsx react ./typings/__tests__/*",
4646
"lint": "eslint src --cache",
4747
"release": "release-it",
@@ -52,6 +52,13 @@
5252
"jest": {
5353
"preset": "react-native"
5454
},
55+
"greenkeeper": {
56+
"ignore": [
57+
"react",
58+
"react-test-renderer",
59+
"metro-react-native-babel-preset"
60+
]
61+
},
5562
"publishConfig": {
5663
"registry": "https://registry.npmjs.org/"
5764
}

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__/render.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ test('getByText, queryByText', () => {
124124

125125
expect(queryByText(/change/i)).toBe(button);
126126
expect(queryByText('InExistent')).toBeNull();
127+
expect(() => queryByText(/fresh/)).toThrow('Expected 1 but found 3');
127128
});
128129

129130
test('getAllByText, queryAllByText', () => {

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/helpers/queryByAPI.js

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,60 @@ import {
1111
getAllByText,
1212
getAllByProps,
1313
} from './getByAPI';
14-
import { logDeprecationWarning } from './errors';
14+
import { ErrorWithStack, logDeprecationWarning } from './errors';
1515

16-
export const queryByName = (instance: ReactTestInstance) => (
17-
name: string | React.ComponentType<*>
18-
) => {
19-
logDeprecationWarning('queryByName', 'getByName');
20-
try {
21-
return getByName(instance)(name);
22-
} catch (error) {
16+
const createQueryByError = (error: Error, callsite: Function) => {
17+
if (error.message.includes('No instances found')) {
2318
return null;
2419
}
20+
throw new ErrorWithStack(error.message, callsite);
2521
};
2622

27-
export const queryByType = (instance: ReactTestInstance) => (
28-
type: React.ComponentType<*>
29-
) => {
30-
try {
31-
return getByType(instance)(type);
32-
} catch (error) {
33-
return null;
34-
}
35-
};
23+
export const queryByName = (instance: ReactTestInstance) =>
24+
function queryByNameFn(name: string | React.ComponentType<*>) {
25+
logDeprecationWarning('queryByName', 'getByName');
26+
try {
27+
return getByName(instance)(name);
28+
} catch (error) {
29+
return createQueryByError(error, queryByNameFn);
30+
}
31+
};
3632

37-
export const queryByText = (instance: ReactTestInstance) => (
38-
text: string | RegExp
39-
) => {
40-
try {
41-
return getByText(instance)(text);
42-
} catch (error) {
43-
return null;
44-
}
45-
};
33+
export const queryByType = (instance: ReactTestInstance) =>
34+
function queryByTypeFn(type: React.ComponentType<*>) {
35+
try {
36+
return getByType(instance)(type);
37+
} catch (error) {
38+
return createQueryByError(error, queryByTypeFn);
39+
}
40+
};
4641

47-
export const queryByProps = (instance: ReactTestInstance) => (props: {
48-
[propName: string]: any,
49-
}) => {
50-
try {
51-
return getByProps(instance)(props);
52-
} catch (error) {
53-
return null;
54-
}
55-
};
42+
export const queryByText = (instance: ReactTestInstance) =>
43+
function queryByTextFn(text: string | RegExp) {
44+
try {
45+
return getByText(instance)(text);
46+
} catch (error) {
47+
return createQueryByError(error, queryByTextFn);
48+
}
49+
};
5650

57-
export const queryByTestId = (instance: ReactTestInstance) => (
58-
testID: string
59-
) => {
60-
try {
61-
return getByTestId(instance)(testID);
62-
} catch (error) {
63-
return null;
64-
}
65-
};
51+
export const queryByProps = (instance: ReactTestInstance) =>
52+
function queryByPropsFn(props: { [propName: string]: any }) {
53+
try {
54+
return getByProps(instance)(props);
55+
} catch (error) {
56+
return createQueryByError(error, queryByPropsFn);
57+
}
58+
};
59+
60+
export const queryByTestId = (instance: ReactTestInstance) =>
61+
function queryByTestIdFn(testID: string) {
62+
try {
63+
return getByTestId(instance)(testID);
64+
} catch (error) {
65+
return createQueryByError(error, queryByTestIdFn);
66+
}
67+
};
6668

6769
export const queryAllByName = (instance: ReactTestInstance) => (
6870
name: string | React.ComponentType<*>

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;

0 commit comments

Comments
 (0)