File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
exercises/user_signup/solutions/codely_next-typescript-middle-out/tests/unit Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -29,4 +29,25 @@ describe("SignUpForm component", () => {
2929 expect ( successMessage ) . toBeInTheDocument ( ) ;
3030 expect ( mockSignUpUser ) . toHaveBeenCalledWith ( { name, email } )
3131 } ) ;
32+
33+ it ( "displays error message after submission fails" , async ( ) => {
34+ render ( < SignUpForm /> ) ;
35+ mockSignUpUser . mockRejectedValue ( new Error ( ) ) ;
36+
37+ const nameField = screen . getByLabelText ( / n a m e / i) ;
38+ const emailField = screen . getByLabelText ( / e m a i l / i) ;
39+
40+ const name = "Jane Doe" ;
41+ const email = "jane@gmail.com" ;
42+
43+ userEvent . type ( nameField , name )
44+ userEvent . type ( emailField , email )
45+
46+ const button = screen . getByRole ( "button" , { name : / s u b m i t / i } )
47+ userEvent . click ( button )
48+
49+ const errorMessage = await screen . findByText ( / a n e r r o r o c u r r e d / i)
50+
51+ expect ( errorMessage ) . toBeInTheDocument ( ) ;
52+ } ) ;
3253} ) ;
You can’t perform that action at this time.
0 commit comments