From af964c04b480aa398b994300cf308fbdfce8be7c Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sun, 31 Jan 2021 15:12:57 -0600 Subject: [PATCH] use fake redux store in component tests --- src/about/AboutDialog.test.tsx | 15 +++++++++++---- src/status-bar/StatusBar.test.tsx | 9 ++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/about/AboutDialog.test.tsx b/src/about/AboutDialog.test.tsx index 5c57eb19..9f47e7a3 100644 --- a/src/about/AboutDialog.test.tsx +++ b/src/about/AboutDialog.test.tsx @@ -11,12 +11,15 @@ import { import userEvent from '@testing-library/user-event'; import React from 'react'; import { Provider } from 'react-redux'; -import { createStore } from 'redux'; -import { rootReducer } from '../reducers'; +import { Store } from 'redux'; import AboutDialog from './AboutDialog'; it('should close when the button is clicked', () => { - const store = createStore(rootReducer); + const store = ({ + getState: jest.fn(() => ({ licenses: { list: null } })), + dispatch: jest.fn(), + subscribe: jest.fn(), + } as unknown) as Store; const i18n = new I18nManager({ locale: 'en' }); const close = jest.fn(); render( @@ -33,7 +36,11 @@ it('should close when the button is clicked', () => { }); it('should manage license dialog open/close', async () => { - const store = createStore(rootReducer); + const store = ({ + getState: jest.fn(() => ({ licenses: { list: null } })), + dispatch: jest.fn(), + subscribe: jest.fn(), + } as unknown) as Store; const i18n = new I18nManager({ locale: 'en' }); render( diff --git a/src/status-bar/StatusBar.test.tsx b/src/status-bar/StatusBar.test.tsx index 85e2a2a0..bc00dff2 100644 --- a/src/status-bar/StatusBar.test.tsx +++ b/src/status-bar/StatusBar.test.tsx @@ -1,12 +1,15 @@ import { fireEvent, render, screen } from '@testing-library/react'; import React from 'react'; import { Provider } from 'react-redux'; -import { createStore } from 'redux'; -import { rootReducer } from '../reducers'; +import { Store } from 'redux'; import StatusBar from './StatusBar'; it('should prevent browser context menu', () => { - const store = createStore(rootReducer); + const store = ({ + getState: jest.fn(), + dispatch: jest.fn(), + subscribe: jest.fn(), + } as unknown) as Store; render(