Skip to content

Commit

Permalink
Added more tests & README update
Browse files Browse the repository at this point in the history
  • Loading branch information
AlemTuzlak committed Apr 23, 2023
1 parent 75feb76 commit 1cb2a31
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ const NestedInput = () => {

<hr />

## Support

If you like the project, please consider supporting us by giving a ⭐️ on Github.
## License

MIT
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remix-hook-form",
"version": "1.0.5",
"version": "1.0.6",
"description": "Utility wrapper around react-hook-form for use with Remix.run",
"type": "module",
"main": "./dist/index.umd.cjs",
Expand Down
44 changes: 42 additions & 2 deletions src/hook/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { renderHook, act, waitFor } from "@testing-library/react";
import { useRemixForm } from "./index";
import {
renderHook,
act,
waitFor,
cleanup,
render,
fireEvent,
} from "@testing-library/react";
import { RemixFormProvider, useRemixForm, useRemixFormContext } from "./index";
import React from "react";

const submitMock = vi.fn();
vi.mock("@remix-run/react", () => ({
Expand Down Expand Up @@ -77,3 +85,35 @@ describe("useRemixForm", () => {
});
});
});

afterEach(cleanup);

describe("RemixFormProvider", () => {
it("should allow the user to submit via the useRemixForm handleSubmit using the context", () => {
const { result } = renderHook(() =>
useRemixForm({
resolver: () => ({ values: {}, errors: {} }),
submitConfig: {
action: "/submit",
},
})
);
const spy = vi.spyOn(result.current, "handleSubmit");

const TestComponent = () => {
const { handleSubmit } = useRemixFormContext();
return <form onSubmit={handleSubmit} data-testid="test"></form>;
};

const { getByTestId } = render(
<RemixFormProvider {...result.current}>
<TestComponent />
</RemixFormProvider>
);

const form = getByTestId("test") as HTMLFormElement;
fireEvent.submit(form);

expect(spy).toHaveBeenCalled();
});
});

0 comments on commit 1cb2a31

Please sign in to comment.