File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -110,11 +110,19 @@ describe('import taxonomy api calls', () => {
110110 expect ( axiosMock . history . put [ 0 ] . url ) . toEqual ( apiUrls . tagsPlanImport ( 1 ) ) ;
111111 } ) ;
112112
113- it ( 'should surface duplicate tag error returned as an array ' , async ( ) => {
114- const duplicateError = 'Request failed with status code 400 ' ;
115- axiosMock . onPost ( apiUrls . createTag ( 1 ) ) . reply ( 400 , [ duplicateError ] ) ;
113+ it ( 'should surface tag errors ' , async ( ) => {
114+ const duplicateMessage = 'Tag with value \'ab\' already exists for taxonomy. ' ;
115+ axiosMock . onPost ( apiUrls . createTag ( 1 ) ) . reply ( 400 , [ duplicateMessage ] ) ;
116116 const { result } = renderHook ( ( ) => useCreateTag ( 1 ) , { wrapper } ) ;
117117
118- await expect ( result . current . mutateAsync ( { value : 'ab' } ) ) . rejects . toEqual ( Error ( duplicateError ) ) ;
118+ try {
119+ await result . current . mutateAsync ( { value : 'ab' } ) ;
120+ // expect: if code reaches this line, the test should fail because an error should have been thrown
121+ expect ( 'This line should not be reached' ) . toBe ( false ) ;
122+ } catch ( error ) {
123+ // we check the response data, not the error message, because of how react-query surfaces errors from axios
124+ // @ts -ignore
125+ expect ( error . response . data ) . toEqual ( [ duplicateMessage ] ) ;
126+ }
119127 } ) ;
120128} ) ;
You can’t perform that action at this time.
0 commit comments