diff --git a/src/generic/notices/NoticesProvider.jsx b/src/generic/notices/NoticesProvider.jsx index 4cbd5f95..e3066b7c 100644 --- a/src/generic/notices/NoticesProvider.jsx +++ b/src/generic/notices/NoticesProvider.jsx @@ -13,7 +13,7 @@ const NoticesProvider = ({ children }) => { useEffect(async () => { if (getConfig().ENABLE_NOTICES) { const data = await getNotices(); - if (data && data.results) { + if (data && data.results && data.results.length > 0) { const { results } = data; setIsRedirected(true); window.location.replace(`${results[0]}?next=${window.location.href}`); diff --git a/src/generic/notices/NoticesProvider.test.jsx b/src/generic/notices/NoticesProvider.test.jsx index 1da5cb3c..fdda35af 100644 --- a/src/generic/notices/NoticesProvider.test.jsx +++ b/src/generic/notices/NoticesProvider.test.jsx @@ -44,7 +44,7 @@ describe('NoticesProvider', () => { delete window.location; window.location = { replace: jest.fn() }; process.env.ENABLE_NOTICES = true; - await act(() => buildAndRender()); + await act(async () => buildAndRender()); expect(window.location.replace).toHaveBeenCalledWith(`${redirectUrl}?next=${window.location.href}`); }); @@ -54,7 +54,7 @@ describe('NoticesProvider', () => { delete window.location; window.location = { replace: jest.fn() }; process.env.ENABLE_NOTICES = true; - await act(() => buildAndRender()); + await act(async () => buildAndRender()); expect(window.location.replace).toHaveBeenCalledTimes(0); expect(window.location.toString() === 'http://localhost/'); });