Skip to content

Commit

Permalink
2023-09-06T13:51:19.077Z
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpocock committed Sep 6, 2023
1 parent 4232988 commit 240fb28
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/035-understanding-the-compiler/127-ts-ignore.explainer.1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expect, it } from "vitest";

const handleFormData = (e: SubmitEvent) => {
e.preventDefault();

// @ts-ignore
const data = new FormData(e.target);
const value = Object.fromEntries(data.entries());
return value;
};

it("Should handle a form submit", () => {
const form = document.createElement("form");
form.innerHTML = `
<input name="name" value="John Doe" />
`;

form.onsubmit = (e) => {
const value = handleFormData(e);
expect(value).toEqual({ name: "John Doe" });
};

form.requestSubmit();

expect.assertions(1);
});
27 changes: 27 additions & 0 deletions src/035-understanding-the-compiler/127-ts-ignore.explainer.2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { expect, it } from "vitest";

const handleFormData = (e: SubmitEvent) => {
e.preventDefault();
const data = new FormData(
// @ts-ignore
e.target,
);
const value = Object.fromEntries(data.entries());
return value;
};

it("Should handle a form submit", () => {
const form = document.createElement("form");
form.innerHTML = `
<input name="name" value="John Doe" />
`;

form.onsubmit = (e) => {
const value = handleFormData(e);
expect(value).toEqual({ name: "John Doe" });
};

form.requestSubmit();

expect.assertions(1);
});
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { expect, it } from "vitest";

const handleFormData = (e: SubmitEvent) => {
e.preventDefault();
const data = new FormData(
// @ts-expect-error
e.target,
);
const value = Object.fromEntries(data.entries());
return value;
};

it("Should handle a form submit", () => {
const form = document.createElement("form");
form.innerHTML = `
<input name="name" value="John Doe" />
`;

form.onsubmit = (e) => {
const value = handleFormData(e);
expect(value).toEqual({ name: "John Doe" });
};

form.requestSubmit();

expect.assertions(1);
});
Empty file.
Empty file.

0 comments on commit 240fb28

Please sign in to comment.