File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
exercises/user_signup/solutions/codely_next-typescript-middle-out/tests/unit Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -3,21 +3,30 @@ import { render, screen } from "@testing-library/react";
33
44import { 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+
611describe ( "SignUpForm component" , ( ) => {
712 it ( "displays success message after correct submission" , async ( ) => {
813 render ( < SignUpForm /> ) ;
9-
14+
1015 const nameField = screen . getByLabelText ( / n a m e / i) ;
1116 const emailField = screen . getByLabelText ( / e m a i l / 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 : / s u b m i t / i } )
1725 userEvent . click ( button )
1826
1927 const successMessage = await screen . findByText ( / t h a n k y o u / i)
2028
2129 expect ( successMessage ) . toBeInTheDocument ( ) ;
30+ expect ( mockSignUpUser ) . toHaveBeenCalledWith ( { name, email } )
2231 } ) ;
2332} ) ;
You can’t perform that action at this time.
0 commit comments