首页 > 解决方案 > 在 React 中查找 td 的值

问题描述

我正在使用酶开发 React 测试,我想达到这个“td”的值

<td className="myCell" key={String(x) + String(y)}>{value}</td>

但使用此代码:

ArrayAreaComponent.find("td").first().render()

我收到:

initialize {
  '0': {
    type: 'tag',
    name: 'td',
    namespace: 'http://www.w3.org/1999/xhtml',
    attribs: [Object: null prototype] { class: 'myCell' },
    'x-attribsNamespace': [Object: null prototype] { class: undefined },
    'x-attribsPrefix': [Object: null prototype] { class: undefined },
    children: [ [Object] ],
    parent: null,
    prev: null,
    next: null,
    root: {
      type: 'root',
      name: 'root',
      namespace: 'http://www.w3.org/1999/xhtml',
      attribs: [Object: null prototype] {},
      'x-attribsNamespace': [Object: null prototype] {},
      'x-attribsPrefix': [Object: null prototype] {},
      children: [Array],
      parent: null,
      prev: null,
      next: null
    }
  },
  options: {
    withDomLvl1: true,
    normalizeWhitespace: false,
    xml: false,
    decodeEntities: true
  },
  length: 1,
  _root: [Circular]
}

如何从该对象中提取值?我在哪里可以找到有关此类对象的更多信息?

标签: reactjstestingenzyme

解决方案


所以最后我通过使用函数解决了

wrapper.containsMatchingElement(<td>{value}</td>).toBeTruthy;

推荐阅读