小编Jon*_*han的帖子

在酶中使用 id 的 wrapper.find 和 jest 找不到元素

我是 Jest 和 Enzyme 测试的新手,我想知道为什么 find 函数不适用于 id。

//来自react的html,只是id增量所在的代码

<div className="App-body">
  <div className="changePage">
    <button className="Selections" onClick={this.decrementPage}>Previous</button>
    <p className="changePageNumber">{this.state.page}</p>
    <button className="Selections" id="increment" onClick={this.incrementPage}>Next</button>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

//测试

it('next page', () => {
  const wrapper = shallow(<Home />)
  const incrementPage = wrapper.find('#increment')
  incrementPage.simulate('click')
  const countState = wrapper.state().page
  expect(countState).toEqual(2)
})
Run Code Online (Sandbox Code Playgroud)

Method “simulate” is meant to be run on 1 node. 0 found instead.
Run Code Online (Sandbox Code Playgroud)

Method “simulate” is meant to be run on 1 node. 0 found instead.
Run Code Online (Sandbox Code Playgroud)

reactjs jestjs enzyme

9
推荐指数
1
解决办法
3万
查看次数

标签 统计

enzyme ×1

jestjs ×1

reactjs ×1