使用JestJS进行单元测试时如何获取组件的道具

时间:2018-08-24 07:24:32

标签: reactjs facebook testing jestjs enzyme

我正在用酶浅。我想获取传递给测试文件中组件的道具。就像在示例中一样,但是我变得不确定。

 <property>
    <name>dfs.namenode.kerberos.principal</name>
    <value>hdfs/_HOST@CORP</value>
  </property>

应该返回props的对象,但是它返回一些jsx对象。

请协助我获取要为其编写测试用例的某些组件的道具。

这是我的代码:

console.log(wrapper.props()) 

1 个答案:

答案 0 :(得分:1)

const wrapper = mount(<MyComponent foo={10} />);
expect(wrapper.props().children).to.equal(10);

编辑:

就像@Must keem指出的那样,这也可以:

const wrapper = mount(<MyComponent foo={10} />);
expect(wrapper.instance().props.foo).to.equal(10);