Skip to content

Commit e1b0b00

Browse files
committed
feat(user-signup): [next-ts-middle-out] 🔵 mock signUpUser
1 parent 2426d16 commit e1b0b00

File tree

1 file changed

+12
-3
lines changed
  • exercises/user_signup/solutions/codely_next-typescript-middle-out/tests/unit

1 file changed

+12
-3
lines changed

exercises/user_signup/solutions/codely_next-typescript-middle-out/tests/unit/SignUpForm.spec.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,30 @@ import { render, screen } from "@testing-library/react";
33

44
import { SignUpForm } from "../../src/components/SignUpForm";
55

6+
import { signUpUser } from "../../src/services/signUpUser";
7+
8+
jest.mock("../../src/services/signUpUser.ts");
9+
const mockSignUpUser = signUpUser as jest.Mock<Promise<void>>;
10+
611
describe("SignUpForm component", () => {
712
it("displays success message after correct submission", async () => {
813
render(<SignUpForm />);
9-
14+
1015
const nameField = screen.getByLabelText(/name/i);
1116
const emailField = screen.getByLabelText(/email/i);
17+
18+
const name = "Jane Doe";
19+
const email = "jane@gmail.com";
1220

13-
userEvent.type(nameField, "Jane Doe")
14-
userEvent.type(emailField, "jane@gmail.com")
21+
userEvent.type(nameField, name)
22+
userEvent.type(emailField, email)
1523

1624
const button = screen.getByRole("button", { name: /submit/i })
1725
userEvent.click(button)
1826

1927
const successMessage = await screen.findByText(/thank you/i)
2028

2129
expect(successMessage).toBeInTheDocument();
30+
expect(mockSignUpUser).toHaveBeenCalledWith({ name, email })
2231
});
2332
});

0 commit comments

Comments
 (0)