Reactjs React test utils SCRYRENDEDDOMComponentswith*不遍历嵌套组件

Reactjs React test utils SCRYRENDEDDOMComponentswith*不遍历嵌套组件,reactjs,redux,jsdom,react-dom,reactjs-testutils,Reactjs,Redux,Jsdom,React Dom,Reactjs Testutils,测试组件时出现问题。我有一个投票组件,它呈现一个投票组件,而投票组件呈现两个标记。使用mocha+chai和react-dom/test-utils库,渲染到jsdom,我想测试两个按钮的渲染效果。当我调用SCryRenderDomComponentSwithTag(component,'button')传递子投票组件时,它返回一个包含两个按钮的集合,但如果传递父项(请参见下文),则返回空集合。我使用了其他带有*方法和相同结果的scryrrendereddom组件。浏览器中的目视检查显示按钮确实

测试组件时出现问题。我有一个
投票
组件,它呈现一个
投票
组件,而
投票
组件呈现两个
标记。使用mocha+chai和react-dom/test-utils库,渲染到jsdom,我想测试两个按钮的渲染效果。当我调用SCryRenderDomComponentSwithTag(component,'button')传递子投票组件时,它返回一个包含两个按钮的集合,但如果传递父项(请参见下文),则返回空集合。我使用了其他带有*方法和相同结果的
scryrrendereddom组件。浏览器中的目视检查显示按钮确实正在渲染。带*
函数的
scryrrendereddomcomponentswith.
函数是否不向下遍历到
componentTree
arg的子级?还是我做错了什么

Voting.js


仅供参考,这是基于完整的堆栈Redux教程(),我一直在跟踪进行必要的更改,以使用当前的API、模式和库。我删除了逻辑以简化这里的代码。在教程示例中,父投票组件通过
renderIntoDocument
呈现到jsdom中<在示例测试中,code>scryRenderedDOMComponentsWithTag被赋予父
投票
组件作为其
组件树
参数,并找到子
投票
组件呈现的按钮-因此我希望它在进行搜索时应该遍历到嵌套组件中。

嗨…我面临同样的问题。你有什么解决办法吗?
import React  from 'react'
import Vote   from './Vote'

const Voting = (props) => (
    <div>
      {
        <Vote {...props} />
      }
    </div>
)

export default Voting
import React from 'react'

class Vote extends React.Component {

  render() {
    return(
      <div className="voting">
        { this.props.pair.map(entry =>
          <button
            key={ entry }
          >
            <h1>{ entry }</h1>
          </button>
        )}
      </div>
    )
  }
}

export default Vote
import React                  from 'react'
import ReactDOM               from 'react-dom'
import {
  renderIntoDocument,
  scryRenderedDOMComponentsWithTag,
  Simulate
}                             from 'react-dom/test-utils'

import { expect }             from 'chai'

import Voting                 from './Voting'

describe('Voting', () => {
  it('renders a pair of buttons', () => {
    const component = renderIntoDocument(
      <Voting pair={["Trainspotting", "28 Days Later"]} />
    )

    const buttons = scryRenderedDOMComponentsWithTag(component, 'button')

    expect(buttons.length).to.equal(2)
  })
})
1) Voting
   renders a pair of buttons:

  AssertionError: expected 0 to equal 2
  + expected - actual

  -0
  +2