File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
exercises/user_signup/solutions/codely_next-typescript-middle-out Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,13 @@ export function SignUpForm() {
1212 const data = new FormData ( ev . target as HTMLFormElement ) ;
1313 const entries = Object . fromEntries ( data . entries ( ) ) as { [ key : string ] : string } ;
1414
15- await signUpUser ( { name : entries . name , email : entries . email } ) ;
16- setFormStatus ( "success" ) ;
15+ return signUpUser ( { name : entries . name , email : entries . email } )
16+ . then ( ( ) => {
17+ setFormStatus ( "success" ) ;
18+ } )
19+ . catch ( ( ) => {
20+ setFormStatus ( "error" ) ;
21+ } ) ;
1722 }
1823
1924 if ( formStatus === "success" ) {
@@ -23,6 +28,9 @@ export function SignUpForm() {
2328 }
2429
2530 return ( < form onSubmit = { handleSubmit } >
31+ {
32+ formStatus === "error" && ( < div > An error ocurred. Please try again</ div > )
33+ }
2634 < Input label = "Name" id = "name" />
2735 < Input type = "email" label = "Email" id = "email" />
2836 < button type = "submit" > Submit</ button >
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const mockSignUpUser = signUpUser as jest.Mock<Promise<void>>;
1111describe ( "SignUpForm component" , ( ) => {
1212 it ( "displays success message after correct submission" , async ( ) => {
1313 render ( < SignUpForm /> ) ;
14+ mockSignUpUser . mockResolvedValue ( ) ;
1415
1516 const nameField = screen . getByLabelText ( / n a m e / i) ;
1617 const emailField = screen . getByLabelText ( / e m a i l / i) ;
You can’t perform that action at this time.
0 commit comments