diff --git a/package.json b/package.json index b9c4a9c..e12ab66 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.js.mustache b/src/index.js.mustache index 78f7e58..280ea8e 100644 --- a/src/index.js.mustache +++ b/src/index.js.mustache @@ -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); } diff --git a/src/react-16-17/index.js b/src/react-16-17/index.js index b55210e..b2e695e 100644 --- a/src/react-16-17/index.js +++ b/src/react-16-17/index.js @@ -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; diff --git a/src/react-16-17/react-utils.js b/src/react-16-17/react-utils.js index 45870bc..6768cc1 100644 --- a/src/react-16-17/react-utils.js +++ b/src/react-16-17/react-utils.js @@ -92,7 +92,9 @@ return null; } - function getRenderedComponentVersion (component, rootInstances) { + function getRenderedComponentVersion (component) { + const rootContainers = window['$testCafeReact16or17RootContainers']; + if (!component.alternate) return component; let component1 = component; @@ -100,8 +102,8 @@ 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; } @@ -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 () {