Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simulate('mouseleave') triggers onMouseLeave event when button is disabled #2502

Closed
2 of 13 tasks
tulsidaskhatri opened this issue Feb 17, 2021 · 2 comments
Closed
2 of 13 tasks

Comments

@tulsidaskhatri
Copy link

tulsidaskhatri commented Feb 17, 2021

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.

Screenshot 2021-02-17 at 21 17 07

Expected behavior

Third test case (should not trigger onMouseLeave when button is disabled) passes.

Your environment

MacOS
Yarn
Visual Studio Code

API

  • shallow
  • mount
  • render

Version

library version
enzyme 3.11.0
react 16.14.0
react-dom 16.14.0
react-test-renderer n/a
adapter (below)

Adapter

  • enzyme-adapter-react-16
  • enzyme-adapter-react-16.2
  • enzyme-adapter-react-16.3
  • enzyme-adapter-react-16.1
  • enzyme-adapter-react-15
  • enzyme-adapter-react-15.4
  • enzyme-adapter-react-14
  • enzyme-adapter-react-13
  • enzyme-adapter-react-helper
  • others ( )
@ljharb
Copy link
Member

ljharb commented Feb 17, 2021

For mount, this behavior is controlled by react-dom/test-utils, so i think you'll need to file a bug on react itself for this.

@tulsidaskhatri
Copy link
Author

reported to react
facebook/react#20966

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants