Skip to content

Commit

Permalink
Merge pull request #180 from kirovboris/fix_get_container
Browse files Browse the repository at this point in the history
Fixed getRenderedComponentVersion, bump version
  • Loading branch information
kirovboris authored Dec 23, 2020
2 parents 98ba90e + c9d66dc commit 20036cb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "testcafe-react-selectors",
"version": "4.1.3",
"version": "4.1.4",
"description": "ReactJS selectors for TestCafe",
"repository": "https://github.com/DevExpress/testcafe-react-selectors",
"main": "lib/index",
Expand Down
10 changes: 7 additions & 3 deletions src/index.js.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ export const ReactSelector = Selector(selector => {
rootEls = getRootElsReact16or17();

if(rootEls.length) {
window['%testCafeReactVersion%'] = '16|17';
window['$testCafeReactSelector'] = selectorReact16or17;
window['$testCafeReact16or17Roots'] = rootEls;
const rootContainers = rootEls.map(root => root.return);
window['%testCafeReactVersion%'] = '16|17';
window['$testCafeReactSelector'] = selectorReact16or17;
window['$testCafeReact16or17Roots'] = rootEls;
window['$testCafeReact16or17RootContainers'] = rootContainers;
foundDOMNodes = selectorReact16or17(selector, false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/react-16-17/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function react16or17Selector (selector, renderedRootIsUnknown, parents = rootEls
}

function getContainer (component) {
let node = renderedRootIsUnknown ? getRenderedComponentVersion(component, rootEls) : component;
let node = renderedRootIsUnknown ? getRenderedComponentVersion(component) : component;

while (!(node.stateNode instanceof Node)) {
if (node.child) node = node.child;
Expand Down
10 changes: 6 additions & 4 deletions src/react-16-17/react-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,18 @@
return null;
}

function getRenderedComponentVersion (component, rootInstances) {
function getRenderedComponentVersion (component) {
const rootContainers = window['$testCafeReact16or17RootContainers'];

if (!component.alternate) return component;

let component1 = component;
let component2 = component.alternate;

while (component1.return) component1 = component1.return;
while (component2.return) component2 = component2.return;

if (rootInstances.indexOf(component1) > -1) return component;
if (rootContainers.indexOf(component1) > -1) return component;

return component.alternate;
}
Expand All @@ -110,7 +112,7 @@
const rootInstances = window['$testCafeReact16or17Roots'].map(rootEl => rootEl.return || rootEl);
const reactInstance = scanDOMNodeForReactInstance(domNode);

return getRenderedComponentVersion(reactInstance, rootInstances);
return getRenderedComponentVersion(reactInstance);
}

function getFoundComponentInstances () {
Expand Down

0 comments on commit 20036cb

Please sign in to comment.