how to select element text with react+enzyme

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

Just what it says. Some example code:

let wrapper = shallow(
); const b = wrapper
4条回答
  •  天涯浪人
    2021-02-02 07:53

    Don't forget that you are passing a node (ReactElement) to shallow function, and there is no HTML attribute class in React. You have to use className.

    From React documentation

    All attributes are camel-cased and the attributes class and for are className and htmlFor, respectively, to match the DOM API specification.

    This test should works

    const wrapper = shallow(
    ); const button = wrapper.find('.btn'); expect(button.text()).to.be.eql('OK');

提交回复
热议问题