Skip to content

Commit a30768e

Browse files
committed
fix: test accuracy
1 parent 600a01c commit a30768e

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/taxonomy/data/apiHooks.test.jsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)