Events like onClick, onMouseEnter and onMouseLeave are not triggered if button is disabled, simulate function works fine for click and mouseenter but it doesn't not work for mouseleave event.
Current behavior
Unlike click and mouseenter, simulate triggers mouseleave for disable button.
import {mount} from 'enzyme';
describe('button', () => {
it('should not trigger onClick when button is disabled', () => {
const handleClick = jest.fn();
const wrapper = mount(
<button disabled onClick={handleClick}>
Text
</button>
);
wrapper.simulate('click');
expect(handleClick).not.toHaveBeenCalled();
});
it('should not trigger onMouseEnter when button is disabled', () => {
const handleMouseEnter = jest.fn();
const wrapper = mount(
<button disabled onMouseEnter={handleMouseEnter}>
Text
</button>
);
wrapper.simulate('mouseenter');
expect(handleMouseEnter).not.toHaveBeenCalled();
});
it('should not trigger onMouseLeave when button is disabled', () => {
const handleMouseLeave = jest.fn();
const wrapper = mount(
<button disabled onMouseLeave={handleMouseLeave}>
Text
</button>
);
wrapper.simulate('mouseleave');
expect(handleMouseLeave).not.toHaveBeenCalled();
});
});
Third test case (should not trigger onMouseLeave when button is disabled) fails.
Expected behavior
Third test case (should not trigger onMouseLeave when button is disabled) passes.
Events like
onClick
,onMouseEnter
andonMouseLeave
are not triggered if button is disabled, simulate function works fine for click and mouseenter but it doesn't not work for mouseleave event.Current behavior
Unlike click and mouseenter, simulate triggers mouseleave for disable button.
Third test case (
should not trigger onMouseLeave when button is disabled
) fails.Expected behavior
Third test case (
should not trigger onMouseLeave when button is disabled
) passes.Your environment
MacOS Yarn Visual Studio Code
API
Version
Adapter