General advices
Main reasons:
Advantages:
Shallow rendering:
Using mount:
// finding a HTML element
const wrapper: ShallowWrapper = shallow(<App/>);
expect(wrapper.find("h1")).to.have.length(1);
// finding a React component
expect(wrapper.find(ProductList)).to.have.length(1);
// contains the an element
expect(wrapper.contains(<span className="num-items">{0}</span>)).to.equal(true);
// check a click event
const noneRadio: ShallowWrapper= wrapper.find("input[value='none']");
noneRadio.simulate("change", {target: {checked: true}});
expect(onSortSpy.called).to.equal(true);
expect(onSortSpy.calledWith("none")).to.equal(true);// class name
expect(wrapper.find('span')).to.have.className('child');
// contains a given node
expect(wrapper).to.contain(<User index={1} />);
// value, checked, disabled, selected
expect(wrapper.find('#checked')).to.be.checked();
expect(wrapper.find('input')).to.have.value('test');
// contains the text
expect(wrapper.find('.msg')).to.not.have.text('Hello world');
// check for the correct style
expect(wrapper).to.have.style("width", WIDTH + "px");
// attr, data
<span id='msg' data-name='child'>test</span>
expect(wrapper).to.have.attr('id', 'msg');
expect(wrapper).to.have.data('name', 'child');
// prop, props
<User index={1} user={{name: 'Jane'}} />
expect(wrapper).to.have.props([ 'index', 'user' ]);