Skip to content

Instantly share code, notes, and snippets.

@hiakku
Last active November 4, 2022 13:47
Show Gist options
  • Save hiakku/90b56de1819a6350c9c473aca0b55c6d to your computer and use it in GitHub Desktop.
Save hiakku/90b56de1819a6350c9c473aca0b55c6d to your computer and use it in GitHub Desktop.
import React from 'react';
import { shallow } from 'enzyme';
import ParentComponent from './index';
it('Test for the button element onChange function', () => {
//To render the root node and returns a shallow wrapper for ParentComponent
const wrapper = shallow(<ParentComponent/>);
//To find the button element
const buttonWrapper = wrapper.find('button');
//To call the onChange function on button named propFunction, with preventDefault
buttonWrapper.simulate('onChange', { preventDefault: jest.fn() });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment