首页 > 解决方案 > 三元运算符用 jest 测试用例

问题描述

我想为以下案例编写一个开玩笑的测试用例,因为它显示了分支覆盖率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?   
  });

标签: reactjsjestjsenzyme

解决方案


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

推荐阅读