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

Commit 2758953

Browse files
author
Brandon Carroll
committed
feat: change the mocked core components
1 parent 49f2b0d commit 2758953

File tree

6 files changed

+40
-16
lines changed

6 files changed

+40
-16
lines changed

src/core-components.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const CoreComponents = [
2+
'ActivityIndicator',
3+
'Button',
4+
'DrawerLayoutAndroid',
5+
'Image',
6+
'Modal',
7+
'Picker',
8+
'RefreshControl',
9+
'ScrollView',
10+
'Switch',
11+
'Text',
12+
'TextInput',
13+
'TouchableHighlight',
14+
'TouchableNativeFeedback',
15+
'TouchableOpacity',
16+
'TouchableWithoutFeedback',
17+
'View',
18+
];
19+
20+
export { CoreComponents };

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Object.keys(rntlFireEvent).forEach(key => {
7777
});
7878

7979
export * from './events';
80+
export * from './core-components';
8081
export * from './get-node-text';
8182
export * from './get-queries-for-element';
8283
export * from './pretty-print';

src/queries/a11y-hint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { queryAllByProp, buildQueries, getPropMatchAsString } from './all-utils';
1+
import { queryAllByProp, buildQueries } from './all-utils';
22

33
const queryAllByA11yHint = queryAllByProp.bind(null, 'accessibilityHint');
44

src/queries/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export * from './a11y-traits';
66
export * from './placeholder';
77
export * from './test-id';
88
export * from './text';
9+
export * from './title';
910
export * from './value';

src/queries/title.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { queryAllByProp, buildQueries } from './all-utils';
2+
3+
const queryAllByTitle = queryAllByProp.bind(null, 'title');
4+
5+
const getMultipleError = (c, title) => `Found multiple elements with the title: ${title}`;
6+
const getMissingError = (c, title) => `Unable to find an element with the title: ${title}`;
7+
8+
const [queryByTitle, getAllByTitle, getByTitle, findAllByTitle, findByTitle] = buildQueries(
9+
queryAllByTitle,
10+
getMultipleError,
11+
getMissingError,
12+
);
13+
14+
export { queryByTitle, queryAllByTitle, getByTitle, getAllByTitle, findAllByTitle, findByTitle };

src/query-helpers.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { prettyPrint } from './pretty-print';
22
import { waitForElement } from './wait-for-element';
33
import { fuzzyMatches, makeNormalizer, matches } from './matches';
4+
import { CoreComponents } from './core-components';
45

56
function debugTree(htmlElement) {
67
const limit = process.env.DEBUG_PRINT_LIMIT || 7000;
@@ -23,20 +24,7 @@ function getMultipleElementsFoundError(message, container) {
2324
);
2425
}
2526

26-
function defaultFilter(node) {
27-
const mockedTypes = [
28-
'Image',
29-
'Text',
30-
'TextInput',
31-
'Modal',
32-
'View',
33-
'RefreshControl',
34-
'ScrollView',
35-
'ActivityIndicator',
36-
'ListView',
37-
'ListViewDataSource',
38-
];
39-
27+
function defaultFilter(node, mockedTypes = CoreComponents) {
4028
return mockedTypes.includes(node.type);
4129
}
4230

@@ -80,7 +68,7 @@ function queryAllByProp(
8068
const matchNormalizer = makeNormalizer({ collapseWhitespace, trim, normalizer });
8169

8270
return Array.from(baseElement.findAll(c => c.props[attribute]))
83-
.filter((node, index) => (filter ? filter(node, index) : defaultFilter(node, index)))
71+
.filter((node, ...args) => (filter ? filter(node, ...args) : defaultFilter(node)))
8472
.filter(({ props }) =>
8573
typeof props[attribute] === 'string'
8674
? matcher(props[attribute], baseElement, match, matchNormalizer)

0 commit comments

Comments
 (0)