Skip to content

Commit d93c952

Browse files
committed
cleanup tests
1 parent bfec6d8 commit d93c952

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

packages/react-zorm/__tests__/use-zorm.test.tsx

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -906,11 +906,11 @@ test.skip("[TYPE ONLY] can narrow validation type to success", () => {
906906
});
907907

908908
test("can validate files", async () => {
909-
const spy = jest.fn();
909+
const refineSpy = jest.fn();
910910

911911
const Schema = z.object({
912912
myFile: z.instanceof(File).refine((file) => {
913-
spy(file.type);
913+
refineSpy(file.type);
914914
return file.type === "image/png";
915915
}, "Only .png images are allowed"),
916916
});
@@ -943,28 +943,15 @@ test("can validate files", async () => {
943943
await userEvent.upload(fileInput, file);
944944
fireEvent.submit(screen.getByTestId("form"));
945945

946-
{
947-
// TEMP TESTS
948-
const form = screen.getByTestId("form") as HTMLFormElement;
949-
expect(fileInput.files?.[0]?.name).toBe("chucknorris.txt");
950-
const formData = new FormData(form);
951-
expect(formData.get("myFile")).toBeInstanceOf(File);
952-
const formFile = formData.get("myFile") as File;
953-
954-
// XXX Bug in jsdom or react testing lib?
955-
// FormData cannot read file from the form.
956-
expect(formFile.name).toBe("chucknorris.txt");
957-
}
958-
959-
expect(spy).toHaveBeenCalledWith("text/plain");
946+
expect(refineSpy).toHaveBeenCalledWith("text/plain");
960947

961948
expect(screen.queryByTestId("error")).toHaveTextContent(
962949
"Only .png images are allowed",
963950
);
964951
});
965952

966953
test("can submit files", async () => {
967-
const spy = jest.fn();
954+
const submitSpy = jest.fn();
968955

969956
const Schema = z.object({
970957
myFile: z.instanceof(File).refine((file) => {
@@ -975,7 +962,7 @@ test("can submit files", async () => {
975962
function Test() {
976963
const zo = useZorm("form", Schema, {
977964
onValidSubmit(e) {
978-
spy(e.data.myFile.name);
965+
submitSpy(e.data.myFile.name);
979966
},
980967
});
981968

@@ -1004,5 +991,5 @@ test("can submit files", async () => {
1004991
await userEvent.upload(fileInput, file);
1005992
fireEvent.submit(screen.getByTestId("form"));
1006993

1007-
expect(spy).toHaveBeenCalledWith("text/plain");
994+
expect(submitSpy).toHaveBeenCalledWith("chucknorris.png");
1008995
});

0 commit comments

Comments
 (0)