三元操作员开玩笑地测试案例

时间:2018-12-05 06:02:18

标签: reactjs jestjs enzyme

我想为后面的案例编写一个开玩笑的测试案例,因为它显示了分支覆盖50%并指出了此代码。

render() {
        const {
          isExit
        } = data;
        const text = isExit ? 'Yes' : 'No';

<LabelValue label="New Line" value={isExit ? 'Yes' : 'No'} />

测试用例

it('Should display the data if API status is complete', () => {
    const wrapper = shallowWithTheme(<DataPage
      orderDetail={{ isExit: true}}
      theme={theme}
    />);

    // what to write here?   
  });

2 个答案:

答案 0 :(得分:0)

expect(wrapper.text()).to.equal('Yes');
expect(wrapper.text()).to.equal('No');

答案 1 :(得分:0)

测试两个条件:

  it('Should display the data if API status is complete', () => {
    const wrapper = shallowWithTheme(<DataPage
      orderDetail={{ isExit: true}}
      theme={theme}
    />);

    expect(wrapper.html()).toMatchSnapshot(); // 1st snapshot
    wrapper
      .setProps({orderDetail: {isExit: false}, theme})
    // check your snapshot with new props :)
    expect(wrapper.html()).toMatchSnapshot(); // 2nd snapshot
  });

祝你好运...

相关问题