From d8d1b50a7b86a90eafa16b81364146c6a52501df Mon Sep 17 00:00:00 2001 From: Piotr Gawron <p.gawron@atcomp.pl> Date: Fri, 24 May 2024 08:31:11 +0200 Subject: [PATCH] test checking if toast is shown --- .../middlewares/error.middleware.test.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/redux/middlewares/error.middleware.test.ts b/src/redux/middlewares/error.middleware.test.ts index 21bc72d7..6c34711b 100644 --- a/src/redux/middlewares/error.middleware.test.ts +++ b/src/redux/middlewares/error.middleware.test.ts @@ -1,6 +1,9 @@ import { store } from '@/redux/store'; +import { showToast } from '@/utils/showToast'; import { errorMiddlewareListener } from './error.middleware'; +jest.mock('../../utils/showToast'); + describe('errorMiddlewareListener', () => { const dispatchSpy = jest.spyOn(store, 'dispatch'); @@ -128,4 +131,27 @@ describe('errorMiddlewareListener', () => { }), ); }); + + it('should toast on access denied', async () => { + const action = { + type: 'action/rejected', + payload: null, + meta: { + requestId: '421', + rejectedWithValue: true, + requestStatus: 'rejected', + }, + error: { + code: '403', + }, + }; + const { getState, dispatch } = store; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-expect-error + await errorMiddlewareListener(action, { getState, dispatch }); + expect(showToast).toHaveBeenCalledWith({ + message: 'Access denied.', + type: 'error', + }); + }); }); -- GitLab