Skip to content

Commit d6d225d

Browse files
authored
fix: getAllBy* methods return more elements than expected (#57)
<!-- Please provide enough information so that others can review your pull request. --> <!-- Keep pull requests small and focused on a single change. --> ### Summary While upgrading the RN dev dep to 0.57.5 our test suite caught a bug, where `getAllBy*` methods would return more elements than expected. This is fixed by making sure we check the proper type of the parameter when we compare it directly to `node.type` (should be a function, but we allowed strings) ### Test plan Updated snapshot (yay! RN fixed the display names of View and Text)
1 parent b82e56c commit d6d225d

File tree

4 files changed

+69
-139
lines changed

4 files changed

+69
-139
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"jest": "^23.6.0",
2525
"metro-react-native-babel-preset": "^0.49.0",
2626
"react": "16.6.1",
27-
"react-native": "^0.57.3",
27+
"react-native": "^0.57.5",
2828
"react-test-renderer": "16.6.1",
2929
"release-it": "^7.6.2",
3030
"strip-ansi": "^5.0.0",

src/__tests__/__snapshots__/shallow.test.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ exports[`shallow rendering React Test Instance 1`] = `
1313
`;
1414

1515
exports[`shallow rendering React elements 1`] = `
16-
<Component>
17-
<Component
16+
<View>
17+
<Text
1818
testID="text-button"
1919
>
2020
Press me
21-
</Component>
22-
</Component>
21+
</Text>
22+
</View>
2323
`;

src/helpers/getByAPI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ErrorWithStack from './errorWithStack';
55
const getNodeByName = (node, name) =>
66
node.type.name === name ||
77
node.type.displayName === name ||
8-
node.type === name;
8+
(typeof name === 'function' && node.type === name);
99

1010
const getNodeByText = (node, text) =>
1111
(getNodeByName(node, 'Text') || getNodeByName(node, 'TextInput')) &&

0 commit comments

Comments
 (0)