how to select element text with react+enzyme

前端 未结 4 1060
不知归路
不知归路 2021-02-02 07:13

Just what it says. Some example code:

let wrapper = shallow(
); const b = wrapper
4条回答
  •  醉酒成梦
    2021-02-02 07:59

    I think @louis-barranqueiro has probably answered your underlying question. That is, you want a CSS selector and so you should have been using className not class.

    However, to try and answer the question of how to select an element's text using the actual example you gave:

    let wrapper = shallow(

    );

    you'd need to use something like an object property selector, e.g.:

    expect(wrapper.find({ class: "btn btn-primary" }).text()).to.equal('OK');

    or prop syntax:

    expect(wrapper.find('[class="btn btn-primary"]').text()).to.equal('OK');

    (or even more explicitly):

    expect(wrapper.find('button[class="btn btn-primary"]').text()).to.equal('OK');

提交回复
热议问题