score:1

Accepted answer

Try the code below

import { shallow } from 'enzyme'
import MyComponent from './MyComponent'

describe('<MyComponent />', () => {
    it('simulates click events', () => {
        const component = shallow(<MyComponent />);
        component.find(Button).simulate("click");
    });
});

EDIT Try the code below:

expect(component
        .find(Button)
        .closest('.settings'))
        .simulate("click");

score:1

The type of element isn't a Button, thats the component name. It is probably a button or input. You can do it like this depending on what element type the node is:

const foo = shallow(<MyComponent />);
foo.find(".settings[button]").simulate("click");

To make this more specific you could always add a class to the button.

Or, per the documentation, if you'd like to you can target it by inputting the component to the test and then finding it that way:

import Bar from '../components/Foo';

const wrapper = shallow(<MyComponent />);
wrapper.find(Bar).simulate("click");

Finally, without any additional imports you can use the display name of the component like so:

const baz = shallow(<MyComponent />);
baz.find('Button').simulate("click");

Related Query

More Query from same tag