开玩笑的测试吐司onClick

时间:2019-12-04 10:12:15

标签: reactjs jestjs

我有一个基本组件,如何创建一个笑话测试来检查react-toastify 的出现?

到目前为止我的测试,如何检查烤面包已开火?:

it("Check toast appears", () => {
    const button = shallow(<FormFail />);
    button.find("button").simulate("click");
    expect(mockCallBack.mock.calls.length).toEqual(1);
});

组件:

class FormFail extends Component {
  constructor(props) {
    super(props);

    this.onClick = this.onClick.bind(this);
  }

  onClick(event) {
    console.log(toast);
    toast.error("Fail", {
      position: toast.POSITION.TOP_RIGHT
    });
    event.preventDefault();
  }

  render() {
    return (
      <div>
        <Container className="App">
          <Button value="button" color="primary" onClick={this.onClick}>
            Press for Fail Toast
          </Button>
        </Container>
      </div>
    );
  }
}

吐司面包显示为:

<div class="Toastify"><div class="Toastify__toast-container Toastify__toast-container--top-right" style="pointer-events: none;"></div></div>

0 个答案:

没有答案