@@ -6,146 +6,40 @@ import { mockErrors } from '../../../mocks'
66
77describe ( 'Form' , ( ) => {
88 test ( 'renders correctly ' , ( ) =>
9- shouldMatchEmotionSnapshot ( < Form errors = { mockErrors } > { ( ) => 'Test' } </ Form > ) )
9+ shouldMatchEmotionSnapshot (
10+ < Form onRawSubmit = { ( ) => { } } errors = { mockErrors } >
11+ { ( ) => 'Test' }
12+ </ Form > ,
13+ ) )
1014 test ( 'renders correctly with node children' , ( ) =>
11- shouldMatchEmotionSnapshot ( < Form errors = { mockErrors } > Test</ Form > ) )
12-
13- test ( 'renders correctly with validate' , ( ) =>
1415 shouldMatchEmotionSnapshot (
15- < Form errors = { mockErrors } validate = { ( ) => ( { test : 'test' } ) } >
16+ < Form onRawSubmit = { ( ) => { } } errors = { mockErrors } >
1617 Test
1718 </ Form > ,
1819 ) )
1920
20- test ( 'renders correctly with onSubmit that return undefined' , ( ) => {
21- const onSubmit = jest . fn ( ( ) => undefined )
22- const onSubmitSuccess = jest . fn ( ( ) => { } )
23- const onSubmitError = jest . fn ( ( ) => { } )
24-
25- return shouldMatchEmotionSnapshot (
26- < Form
27- errors = { mockErrors }
28- onSubmitSuccess = { onSubmitSuccess }
29- onSubmit = { onSubmit }
30- onSubmitError = { onSubmitError }
31- >
32- < button type = "submit" > Submit</ button >
33- </ Form > ,
34- {
35- transform : async ( { getByText } ) => {
36- await userEvent . click ( getByText ( 'Submit' ) )
37- expect ( onSubmit ) . toBeCalledTimes ( 1 )
38- await waitFor ( ( ) => expect ( onSubmitSuccess ) . toBeCalledTimes ( 1 ) )
39- expect ( onSubmitError ) . toBeCalledTimes ( 0 )
40- } ,
41- } ,
42- )
43- } )
44-
45- test ( 'renders correctly with onSubmit that return {}' , ( ) => {
46- const onSubmit = jest . fn ( ( ) => Promise . resolve ( { } ) )
47- const onSubmitSuccess = jest . fn ( ( ) => { } )
48- const onSubmitError = jest . fn ( ( ) => { } )
49-
50- return shouldMatchEmotionSnapshot (
51- < Form
52- errors = { mockErrors }
53- onSubmitSuccess = { onSubmitSuccess }
54- onSubmit = { onSubmit }
55- onSubmitError = { onSubmitError }
56- >
57- < button type = "submit" > Submit</ button >
58- </ Form > ,
59- {
60- transform : async ( { getByText } ) => {
61- await userEvent . click ( getByText ( 'Submit' ) )
62- expect ( onSubmit ) . toBeCalledTimes ( 1 )
63- await waitFor ( ( ) => expect ( onSubmitError ) . toBeCalledTimes ( 1 ) )
64- expect ( onSubmitSuccess ) . toBeCalledTimes ( 0 )
65- } ,
66- } ,
67- )
68- } )
69-
70- test ( 'renders correctly with onSubmit that throw' , ( ) => {
71- const onSubmit = jest . fn ( ( ) => Promise . reject ( ) )
72- const onSubmitSuccess = jest . fn ( ( ) => { } )
73- const onSubmitError = jest . fn ( ( ) => { } )
74-
75- return shouldMatchEmotionSnapshot (
76- < Form
77- errors = { mockErrors }
78- onSubmitSuccess = { onSubmitSuccess }
79- onSubmit = { onSubmit }
80- onSubmitError = { onSubmitError }
81- >
82- < button type = "submit" > Submit</ button >
83- </ Form > ,
84- {
85- transform : async ( { getByText } ) => {
86- await userEvent . click ( getByText ( 'Submit' ) )
87- expect ( onSubmit ) . toBeCalledTimes ( 1 )
88- await waitFor ( ( ) => expect ( onSubmitError ) . toBeCalledTimes ( 1 ) )
89- expect ( onSubmitSuccess ) . toBeCalledTimes ( 0 )
90- } ,
91- } ,
92- )
93- } )
94-
95- test ( 'renders correctly with parseSubmitException' , ( ) => {
96- const onSubmit = jest . fn ( ( ) => Promise . reject ( new Error ( 'error' ) ) )
97- const onSubmitSuccess = jest . fn ( ( ) => { } )
98- const onSubmitError = jest . fn ( ( ) => { } )
99- const parseSubmitException = jest . fn ( ( ) => 'parsed error' )
100-
101- return shouldMatchEmotionSnapshot (
21+ test ( 'renders correctly with validate' , ( ) =>
22+ shouldMatchEmotionSnapshot (
10223 < Form
24+ onRawSubmit = { ( ) => { } }
10325 errors = { mockErrors }
104- onSubmitSuccess = { onSubmitSuccess }
105- onSubmit = { onSubmit }
106- onSubmitError = { onSubmitError }
107- parseSubmitException = { parseSubmitException }
26+ validate = { ( ) => ( { test : 'test' } ) }
10827 >
109- < button type = "submit" > Submit </ button >
28+ Test
11029 </ Form > ,
111- {
112- transform : async ( { getByText } ) => {
113- await userEvent . click ( getByText ( 'Submit' ) )
114- expect ( onSubmit ) . toBeCalledTimes ( 1 )
115- await waitFor ( ( ) => expect ( onSubmitError ) . toBeCalledTimes ( 1 ) )
116- await waitFor ( ( ) => expect ( parseSubmitException ) . toBeCalledTimes ( 1 ) )
117- expect ( parseSubmitException ) . toBeCalledWith ( new Error ( 'error' ) )
118- expect ( onSubmitSuccess ) . toBeCalledTimes ( 0 )
119- } ,
120- } ,
121- )
122- } )
30+ ) )
12331
124- test ( 'renders correctly with onRawSubmit which should take precedence' , ( ) => {
125- const onSubmit = jest . fn ( ( ) => Promise . reject ( new Error ( 'error' ) ) )
126- const onSubmitSuccess = jest . fn ( ( ) => { } )
32+ test ( 'renders correctly with onRawSubmit' , ( ) => {
12733 const onRawSubmit = jest . fn ( ( ) => { } )
128- const onSubmitError = jest . fn ( ( ) => { } )
129- const parseSubmitException = jest . fn ( ( ) => 'parsed error' )
13034
13135 return shouldMatchEmotionSnapshot (
132- < Form
133- errors = { mockErrors }
134- onSubmitSuccess = { onSubmitSuccess }
135- onSubmit = { onSubmit }
136- onSubmitError = { onSubmitError }
137- parseSubmitException = { parseSubmitException }
138- onRawSubmit = { onRawSubmit }
139- >
36+ < Form errors = { mockErrors } onRawSubmit = { onRawSubmit } >
14037 < button type = "submit" > Submit</ button >
14138 </ Form > ,
14239 {
14340 transform : async ( { getByText } ) => {
14441 await userEvent . click ( getByText ( 'Submit' ) )
14542 await waitFor ( ( ) => expect ( onRawSubmit ) . toBeCalledTimes ( 1 ) )
146- expect ( onSubmit ) . toBeCalledTimes ( 0 )
147- expect ( onSubmitError ) . toBeCalledTimes ( 0 )
148- expect ( parseSubmitException ) . toBeCalledTimes ( 0 )
14943 } ,
15044 } ,
15145 )
0 commit comments