Skip to content

Commit

Permalink
:(
Browse files Browse the repository at this point in the history
  • Loading branch information
taraepp committed Jan 16, 2025
1 parent cff6b02 commit f7bdab2
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions services/common/src/components/forms/RenderResetButton.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from "react";
import { render, fireEvent } from "@testing-library/react";
import RenderResetButton from "./RenderResetButton";
import { ReduxWrapper } from "@mds/common/tests/utils/ReduxWrapper";
import FormWrapper from "./FormWrapper";
import * as reduxForm from "redux-form";

const initialState = {
form: {
FORM_NAME: {
values: { field_name: "some value" }
}
}
}

describe("RenderResetButton component", () => {
const resetFunction = jest.fn();
const buttonText = "Clear Form";

const resetSpy = jest.spyOn(reduxForm, "reset");

test("calls the reset function on click", () => {
const { getByText } = render(
<ReduxWrapper initialState={initialState}>
<FormWrapper
name="FORM_NAME"
onReset={resetFunction}
onSubmit={jest.fn()}
>
<RenderResetButton buttonText={buttonText} />
</FormWrapper>
</ReduxWrapper>
);

const button = getByText(buttonText);
fireEvent.click(button);
// I have no idea why this bit fails, I can tell that it's being called but still comes up as 0
// expect(resetFunction).toHaveBeenCalledTimes(1);
expect(resetSpy).toHaveBeenCalledTimes(1);
});
});

0 comments on commit f7bdab2

Please sign in to comment.