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(<div><button className='btn btn-primary'>OK</button></div>);
const button = wrapper.find('.btn');
expect(button.text()).to.be.eql('OK');
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…