【问题标题】:Enzyme shallow renderer returns null node element酶浅渲染器返回空节点元素
【发布时间】:2018-09-13 20:00:00
【问题描述】:

我遇到了 Enzyme 浅层渲染器的问题。我的 wrapper.root.node 即使对于简单的 div 元素也会返回 null。

        const wrapper = shallow(
            <div>asd</div>
        );

这里是 ShallowWrapper 对象。节点元素为空,但未渲染属性包含正常渲染的对象。这是为什么 ?

ShallowWrapper {
  "complexSelector": ComplexSelector {
    "buildPredicate": [Function],
    "childrenOfNode": [Function],
    "findWhereUnwrapped": [Function],
  },
  "length": 1,
  "node": null,
  "nodes": Array [
    null,
  ],
  "options": Object {},
  "renderer": ReactShallowRenderer {
    "_instance": null,
    "getRenderOutput": [Function],
    "render": [Function],
  },
  "root": [Circular],
  "unrendered": <div>
    asd
</div>,
}

【问题讨论】:

    标签: javascript reactjs jestjs enzyme


    【解决方案1】:

    好的,由 jest 'react-dom' mock 引起的问题:

    jest.mock('react-dom')
    

    通过将单元测试移动到其他文件中解决了问题。

    【讨论】:

      猜你喜欢
      • 2018-09-25
      • 2018-04-03
      • 1970-01-01
      • 1970-01-01
      • 2016-08-31
      • 1970-01-01
      • 1970-01-01
      • 2020-08-26
      • 2020-03-12
      相关资源
      最近更新 更多