Answers for "testing a function in jest on click react"

0

testing a function in jest on click react

import React from 'react';
import { shallow } from 'enzyme';
import Button from './Button';

describe('Test Button component', () => {
  it('Test click event', () => {
    const mockCallBack = jest.fn();

    const button = shallow((<Button onClick={mockCallBack}>Ok!</Button>));
    button.find('button').simulate('click');
    expect(mockCallBack.mock.calls.length).toEqual(1);
  });
});
Posted by: Guest on December-18-2020

Code answers related to "testing a function in jest on click react"

Code answers related to "Javascript"

Browse Popular Code Answers by Language