Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

Commit 63a01fb

Browse files
author
Brandon Carroll
committed
v3 release candidate
1 parent 84804ad commit 63a01fb

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "native-testing-library",
3-
"version": "3.0.0-beta.5",
3+
"version": "0.0.0-semantically-released",
44
"description": "Simple and complete React Native testing utilities that encourage good testing practices.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/lib/__tests__/queries.find.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ test('find asynchronously finds elements', async () => {
3535
<Image accessibilityLabel="test-label" src="/lucy-ricardo.png" />
3636
<Image accessibilityHint="test-hint" src="/lucy-ricardo.png" />
3737
<View accessibilityRole="dialog" />
38+
<View accessibilityRole="fake" />
3839
</View>,
3940
);
4041

42+
// Things get annoying querying accessibilityTraits with `queryByRole`
43+
jest.spyOn(console, 'warn').mockImplementation(() => {});
44+
4145
await expect(findByHintText('test-hint')).resolves.toBeTruthy();
4246
await expect(findAllByHintText('test-hint')).resolves.toHaveLength(1);
4347

@@ -74,8 +78,14 @@ test('find asynchronously finds elements', async () => {
7478
await expect(findByRole(['none'])).resolves.toBeTruthy();
7579
await expect(findAllByRole(['none'])).resolves.toHaveLength(1);
7680

81+
await expect(findByRole('fake', {}, { timeout: 50 })).rejects.toThrow();
82+
7783
await expect(findByTestId('test-id')).resolves.toBeTruthy();
7884
await expect(findAllByTestId('test-id')).resolves.toHaveLength(1);
85+
86+
console.warn.mock.calls.forEach(([message]) => {
87+
expect(message).toMatch(/Found elements matching accessibilityTraits/);
88+
});
7989
});
8090

8191
test('find rejects when something cannot be found', async () => {

src/lib/queries/role.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,30 @@ function queryAllByRole(testRenderer, value, { filter = n => n } = {}) {
4444
const role = node.getProp('accessibilityRole');
4545
const traits = node.getProp('accessibilityTraits');
4646

47-
if (role === value && validRoles.includes(value)) {
47+
if (role === value) {
48+
if (!validRoles.includes(value)) {
49+
throw new Error(
50+
`Found a match for accessibilityRole: "${value}", but "${value}" is not a valid accessibilityRole.`,
51+
);
52+
}
53+
4854
return true;
4955
} else if (traits) {
5056
const arrayTraits = Array.isArray(traits) ? traits : [traits];
5157
const arrayValue = Array.isArray(value) ? value : [value];
58+
const traitMatch = arrayTraits.every(
59+
i => arrayValue.indexOf(i) > -1 && validTraits.includes(i),
60+
);
61+
62+
if (traitMatch) {
63+
console.warn(
64+
`Found elements matching accessibilityTraits: \`${JSON.stringify(
65+
arrayValue,
66+
)}\`, which will soon be deprecated. Please transition to using accessibilityRoles.`,
67+
);
68+
}
5269

53-
return arrayTraits.every(i => arrayValue.indexOf(i) > -1 && validTraits.includes(i));
70+
return traitMatch;
5471
}
5572

5673
return false;

0 commit comments

Comments
 (0)