{"size": 924, "ext": "js", "max_stars_repo_path": "src/Components/FormWrapper/index.test.js", "max_stars_repo_name": "iamrahulrnair/drum-root", "max_stars_repo_stars_event_min_datetime": "2019-11-03T23:39:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T10:56:50.000Z", "max_issues_repo_path": "src/Components/FormWrapper/index.test.js", "max_issues_repo_name": "iamrahulrnair/drum-root", "max_issues_repo_issues_event_min_datetime": "2019-11-06T19:52:33.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T19:02:29.000Z", "max_forks_repo_path": "src/Components/FormWrapper/index.test.js", "max_forks_repo_name": "iamrahulrnair/drum-root", "max_forks_repo_forks_event_min_datetime": "2019-10-29T22:24:50.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T03:52:21.000Z"}
{"max_stars_count": 60, "max_issues_count": 126, "max_forks_count": 199, "avg_line_length": 29.8064516129, "max_line_length": 78, "alphanum_fraction": 0.6461038961}
import React from 'react';
import { render, fireEvent, wait } from '@testing-library/react';
import FormWrapper from './index';

const mockSubmitFn = jest.fn();

const Button = () => <button type="submit">Submit</button>;

describe('FormWrapper component', () => {
  test('should render properly', async () => {
    const errorMessage = 'Submit Error';
    const { getByText, rerender } = render(
      <FormWrapper onSubmit={mockSubmitFn.mockResolvedValueOnce()}>
        <Button />
      </FormWrapper>
    );
    await wait(() => fireEvent.click(getByText(/submit/i)));
    expect(getByText(/success/i)).toBeInTheDocument();
    rerender(
      <FormWrapper
        onSubmit={mockSubmitFn.mockRejectedValueOnce(new Error(errorMessage))}
      >
        <Button />
      </FormWrapper>
    );
    await wait(() => fireEvent.click(getByText(/submit/i)));

    expect(getByText(errorMessage)).toBeInTheDocument();
  });
});
