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

Commit 53455a9

Browse files
committed
refactor: rename baseElement and container
1 parent 4754e0a commit 53455a9

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

examples/__tests__/react-intl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const renderWithReactIntl = component => {
3939
setupTests();
4040

4141
test('it should render FormattedDate and have a formatted pt date', () => {
42-
const { container, rootInstance } = renderWithReactIntl(<FormatDateView />);
42+
const { container } = renderWithReactIntl(<FormatDateView />);
4343

44-
getByText({ container, rootInstance }, '11/03/2019');
44+
getByText(container, '11/03/2019');
4545
});

src/get-queries-for-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as defaultQueries from './queries';
1212
function getQueriesForElement(container, queries = defaultQueries) {
1313
return Object.keys(queries).reduce((helpers, key) => {
1414
const fn = queries[key];
15-
helpers[key] = fn.bind(null, { container: container, rootInstance: container.root });
15+
helpers[key] = fn.bind(null, container);
1616
return helpers;
1717
}, {});
1818
}

src/queries.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ const queryByA11yRole = queryByProp.bind(null, 'accessibilityRole');
1818
const queryAllByA11yRole = queryAllByProp.bind(null, 'accessibilityRole');
1919

2020
function queryAllByText(
21-
{ rootInstance },
21+
container,
2222
text,
2323
{ types = [Text, TextInput], exact = true, collapseWhitespace, trim, normalizer } = {},
2424
) {
25+
const rootInstance = container.root;
2526
const matcher = exact ? matches : fuzzyMatches;
2627
const matchNormalizer = makeNormalizer({ collapseWhitespace, trim, normalizer });
2728

@@ -42,8 +43,8 @@ function queryByText(...args) {
4243
// 1. The error messages are specific to each one and depend on arguments
4344
// 2. The stack trace will look better because it'll have a helpful method name.
4445

45-
function getAllByTestId({ rootInstance, container }, id, ...rest) {
46-
const els = queryAllByTestId({ rootInstance, container }, id, ...rest);
46+
function getAllByTestId(container, id, ...rest) {
47+
const els = queryAllByTestId(container, id, ...rest);
4748
if (!els.length) {
4849
throw getElementError(`Unable to find an element with the testID: ${id}`, container);
4950
}
@@ -54,8 +55,8 @@ function getByTestId(...args) {
5455
return firstResultOrNull(getAllByTestId, ...args);
5556
}
5657

57-
function getAllByA11yRole({ rootInstance, container }, value, ...rest) {
58-
const els = queryAllByA11yRole({ rootInstance, container }, value, ...rest);
58+
function getAllByA11yRole(container, value, ...rest) {
59+
const els = queryAllByA11yRole(container, value, ...rest);
5960
if (!els.length) {
6061
throw getElementError(`Unable to find an element by accessibilityRole="${value}".`, container);
6162
}
@@ -66,8 +67,8 @@ function getByA11yRole(...args) {
6667
return firstResultOrNull(getAllByA11yRole, ...args);
6768
}
6869

69-
function getAllByValue({ rootInstance, container }, value, ...rest) {
70-
const els = queryAllByValue({ rootInstance, container }, value, ...rest);
70+
function getAllByValue(container, value, ...rest) {
71+
const els = queryAllByValue(container, value, ...rest);
7172
if (!els.length) {
7273
throw getElementError(`Unable to find an element with the value: ${value}.`, container);
7374
}
@@ -78,8 +79,8 @@ function getByValue(...args) {
7879
return firstResultOrNull(getAllByValue, ...args);
7980
}
8081

81-
function getAllByA11yLabel({ rootInstance, container }, text, ...rest) {
82-
const els = queryAllByA11yLabel({ rootInstance, container }, text, ...rest);
82+
function getAllByA11yLabel(container, text, ...rest) {
83+
const els = queryAllByA11yLabel(container, text, ...rest);
8384
if (!els.length) {
8485
throw getElementError(`Unable to find an element by accessibilityLabel="${text}"`, container);
8586
}
@@ -90,8 +91,8 @@ function getByA11yLabel(...args) {
9091
return firstResultOrNull(getAllByA11yLabel, ...args);
9192
}
9293

93-
function getAllByPlaceholder({ rootInstance, container }, text, ...rest) {
94-
const els = queryAllByPlaceholder({ rootInstance, container }, text, ...rest);
94+
function getAllByPlaceholder(container, text, ...rest) {
95+
const els = queryAllByPlaceholder(container, text, ...rest);
9596
if (!els.length) {
9697
throw getElementError(
9798
`Unable to find an element with the placeholder text of: ${text}`,
@@ -105,8 +106,8 @@ function getByPlaceholder(...args) {
105106
return firstResultOrNull(getAllByPlaceholder, ...args);
106107
}
107108

108-
function getAllByText({ rootInstance, container }, text, ...rest) {
109-
const els = queryAllByText({ rootInstance, container }, text, ...rest);
109+
function getAllByText(container, text, ...rest) {
110+
const els = queryAllByText(container, text, ...rest);
110111
if (!els.length) {
111112
throw getElementError(
112113
`Unable to find an element with the text: ${text}. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.`,
@@ -121,9 +122,9 @@ function getByText(...args) {
121122
}
122123

123124
function makeFinder(getter) {
124-
return (testInstance, text, options, waitForElementOptions) =>
125+
return (testContainer, text, options, waitForElementOptions) =>
125126
waitForElement(
126-
(instance = testInstance) => getter(instance, text, options),
127+
(container = testContainer) => getter(container, text, options),
127128
waitForElementOptions,
128129
);
129130
}

src/query-helpers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ function defaultFilter(node) {
6666

6767
function queryAllByProp(
6868
attribute,
69-
{ container, rootInstance },
69+
container,
7070
text,
7171
{ filter, exact = true, collapseWhitespace, trim, normalizer } = {},
7272
) {
73+
const rootInstance = container.root;
7374
const matcher = exact ? matches : fuzzyMatches;
7475
const matchNormalizer = makeNormalizer({ collapseWhitespace, trim, normalizer });
7576
const allNodes = Array.from(rootInstance.findAll(c => c.props[attribute]));

src/wait-for-element.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ function waitForElement(callback, { container, interval = 50, timeout = 4500 } =
2222

2323
function onMutation() {
2424
try {
25-
const result = container
26-
? callback({ container, rootInstance: container.root })
27-
: callback();
25+
const result = container ? callback(container) : callback();
2826
if (result) {
2927
onDone(null, result);
3028
}

0 commit comments

Comments
 (0)