Jest Enzyme测试用例范围

时间:2019-01-17 04:06:16

标签: reactjs jestjs enzyme

需要使用笑话和酶来为以下功能编写测试用例的帮助...下面的asView是一个为我的案例返回视图的功能...

showRowSubView = (rowModel) => {
    if (rowModel.has('tiers')) {
      const record = rowModel.toJSON();
      /* eslint-disable react/no-danger */
      const template = asView(() =>
        record.tiers.map(item => (
          <table >
            <tbody>
              <tr>
                <td>
                  <div className="tiersTable" dangerouslySetInnerHTML={this.returnTemplate(item)} />
                </td>
              </tr>
            </tbody>
          </table>
        )),
      );
      return template;
    }
    return null;
  };

1 个答案:

答案 0 :(得分:0)

类似这样的东西:

const model = {
 tiers:['a','b','c']
};

it('showRowSubView',()=>{
 const wrapper = shallow(<ShowRowSubView rowModel={model }/>);
 expect(wrapper).toMatchSnapshot();
});