From f5891222b3fffc2a202c96ca59ffb4ccf437e396 Mon Sep 17 00:00:00 2001 From: Mozafar Haider Date: Tue, 10 Sep 2024 08:26:16 +0100 Subject: [PATCH] fix: ensure logic does not fail with empty response pre v40 --- src/pages/ManualInstall/ManualInstall.js | 11 +++++++++-- src/pages/ManualInstall/ManualInstall.spec.js | 13 ++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/pages/ManualInstall/ManualInstall.js b/src/pages/ManualInstall/ManualInstall.js index 437263f..f76dba3 100644 --- a/src/pages/ManualInstall/ManualInstall.js +++ b/src/pages/ManualInstall/ManualInstall.js @@ -43,10 +43,17 @@ const UploadButton = () => { setIsUploading(true) try { const response = await uploadApp(event.target.files[0]) - const body = await response.json() + + // using response.text() rather .json() to avoid breaking in { it('should allow navigating to the app', async () => { jest.spyOn(global, 'fetch').mockResolvedValueOnce({ - json: () => Promise.resolve({ app_hub_id: 'some_apphub_id' }), + text: () => + Promise.resolve( + JSON.stringify({ app_hub_id: 'some_apphub_id' }) + ), }) const { getByTestId, getByText, findByText } = renderWithProvider( @@ -57,7 +60,7 @@ describe('Manual Install', () => { it('should work with an empty response (pre v41)', async () => { jest.spyOn(global, 'fetch').mockResolvedValueOnce({ - json: () => Promise.resolve(), + text: () => null, }) const { getByTestId, findByText, queryByText } = renderWithProvider( @@ -73,11 +76,7 @@ describe('Manual Install', () => { }) it('should show an error if it fails', async () => { - jest.spyOn(global, 'fetch').mockResolvedValueOnce({ - json: () => { - throw 'upload failed' - }, - }) + jest.spyOn(global, 'fetch').mockRejectedValue('upload failed') const { getByTestId, findByText, queryByText } = renderWithProvider(