【问题标题】:react test, how to test for unchecked state?反应测试,如何测试未检查状态?
【发布时间】:2015-07-13 14:55:03
【问题描述】:

我有一个使用模拟点击的测试,它测试输入检查。当输入未被选中时,我将如何测试?

    var input = TestUtils.findRenderedDOMComponentWithTag(instance, "input");

    TestUtils.Simulate.click(input);

    var data = this.stubbed.getLastPublished();

    expect(data.topic === 'selected');
    expect(data.id === 1);
    expect(input.checked === true);

【问题讨论】:

  • expect(input.checked !== true);expect(input.checked === false); 怎么样?

标签: javascript unit-testing reactjs


【解决方案1】:

感谢我使用的回复:

TestUtils.Simulate.click(input, { target: {
        checked: false }
    });

【讨论】:

    猜你喜欢
    • 2018-01-10
    • 2016-06-03
    • 2023-02-06
    • 2014-01-27
    • 1970-01-01
    • 1970-01-01
    • 2019-11-16
    • 2017-06-24
    • 2019-03-08
    相关资源
    最近更新 更多