1 回答
TA贡献1891条经验 获得超3个赞
试试这个方法,
const setup = () => shallow(<App />);
const findByTestAttr = (wrapper, val) => wrapper.find(`[data-test='${val}']`);
test('error message disappears when counter larger than 0', () => {
const wrapper = setup();
//Decrement opration
const decrementButton = findByTestAttr(wrapper, 'decrement-button');
decrementButton.simulate('click');
let errorMessage = findByTestAttr(wrapper, 'below-zero-error-message');
console.log('Error ==>',wrapper.debug());
expect(errorMessage.length).toBe(1);
// Increment Operation
const incrementButton = findByTestAttr(wrapper, 'increment-button');
incrementButton.simulate('click');
console.log('No error ==>',wrapper.debug());
errorMessage = findByTestAttr(wrapper, 'below-zero-error-message');
expect(errorMessage.length).toBe(0);
});
如果您遇到任何问题,请告诉我。
添加回答
举报