我想断言当一个禁用的按钮被点击时,它的onClick事件不会被触发。我如何用酶来做到这一点?请参阅下面的示例代码。谢谢!
示例按钮.jsx:
import React from 'react';
const SampleButton = () => (
<button
disabled={true}
onClick={() => console.log('You clicked me!')}
test-attr="button"
type="button"
>
Click Me
</button>
);
export default SampleButton;
sampleButton.test.jsx:
import React from 'react';
import { shallow } from 'enzyme';
import SampleButton from './sampleButton';
test('cannot click button if disabled', () => {
const wrapper = shallow(<SampleButton />);
const button = wrapper.find('[test-attr="button"]');
button.simulate('click');
// assert that `onClick` has not been fired
});
呼啦一阵风
相关分类