diff --git a/src/about/AboutDialog.test.tsx b/src/about/AboutDialog.test.tsx index d47465db..ce25204c 100644 --- a/src/about/AboutDialog.test.tsx +++ b/src/about/AboutDialog.test.tsx @@ -10,7 +10,7 @@ import AboutDialog from './AboutDialog'; it('should close when the button is clicked', () => { const close = jest.fn(); - const dialog = testRender( close()} />); + const [dialog] = testRender( close()} />); userEvent.click(dialog.getByLabelText('Close')); @@ -18,7 +18,9 @@ it('should close when the button is clicked', () => { }); it('should manage license dialog open/close', async () => { - const dialog = testRender( undefined} />); + const [dialog] = testRender( + undefined} />, + ); userEvent.click(dialog.getByText('Software Licenses')); diff --git a/src/editor/Editor.test.tsx b/src/editor/Editor.test.tsx index bf6b4bd7..32406c66 100644 --- a/src/editor/Editor.test.tsx +++ b/src/editor/Editor.test.tsx @@ -19,14 +19,14 @@ function getTextArea(editor: RenderResult): HTMLTextAreaElement { } it('should focus the text area', () => { - const editor = testRender(); + const [editor] = testRender(); expect(getTextArea(editor)).toHaveFocus(); }); describe('context menu', () => { it('should show the context menu', async () => { - const editor = testRender(); + const [editor] = testRender(); fireEvent.contextMenu(editor.getByText('Write your program here...')); @@ -36,7 +36,7 @@ describe('context menu', () => { }); it('should hide the context menu when Escape is pressed', async () => { - const editor = testRender(); + const [editor] = testRender(); fireEvent.contextMenu(editor.getByText('Write your program here...')); diff --git a/src/explorer/Explorer.test.tsx b/src/explorer/Explorer.test.tsx index c95dcbcc..1343ec50 100644 --- a/src/explorer/Explorer.test.tsx +++ b/src/explorer/Explorer.test.tsx @@ -8,7 +8,7 @@ import Explorer from './Explorer'; describe('archive button', () => { it('should be enabled if there are files', () => { - const explorer = testRender(, { + const [explorer] = testRender(, { fileStorage: { fileNames: ['test.file'] }, }); @@ -16,7 +16,7 @@ describe('archive button', () => { }); it('should be disabled if there are no files', () => { - const explorer = testRender(, { + const [explorer] = testRender(, { fileStorage: { fileNames: [] }, }); @@ -26,7 +26,7 @@ describe('archive button', () => { describe('list item', () => { it('should show/hide buttons on hover', () => { - const explorer = testRender(, { + const [explorer] = testRender(, { fileStorage: { fileNames: ['test.file'] }, }); @@ -45,7 +45,7 @@ describe('list item', () => { }); it('should not focus buttons on click', () => { - const explorer = testRender(, { + const [explorer] = testRender(, { fileStorage: { fileNames: ['test.file'] }, }); diff --git a/src/status-bar/StatusBar.test.tsx b/src/status-bar/StatusBar.test.tsx index 99fcfecd..1c0de312 100644 --- a/src/status-bar/StatusBar.test.tsx +++ b/src/status-bar/StatusBar.test.tsx @@ -9,7 +9,7 @@ import { BleConnectionState } from '../ble/reducers'; import StatusBar from './StatusBar'; it('should prevent browser context menu', () => { - const statusBar = testRender(, { + const [statusBar] = testRender(, { ble: { connection: BleConnectionState.Disconnected, deviceName: '' }, }); @@ -19,7 +19,7 @@ it('should prevent browser context menu', () => { it('should show popover when hub name is clicked', async () => { const testHubName = 'Test hub'; - const statusBar = testRender(, { + const [statusBar] = testRender(, { ble: { connection: BleConnectionState.Connected, deviceName: testHubName, @@ -38,7 +38,7 @@ it('should show popover when hub name is clicked', async () => { it('should show popover when battery is clicked', async () => { const testHubName = 'Test hub'; - const statusBar = testRender(, { + const [statusBar] = testRender(, { ble: { connection: BleConnectionState.Connected, deviceName: testHubName, diff --git a/test/index.tsx b/test/index.tsx index 1a610a9e..808a7ab1 100644 --- a/test/index.tsx +++ b/test/index.tsx @@ -132,19 +132,22 @@ export function lookup(obj: unknown, id: string): string | undefined { * * @param component The component to render. * @param state Any state required by the component. - * @returns The render result. + * @returns The render result and a spy on the dispatch method. */ export const testRender = ( component: ReactElement, state?: PreloadedState, -): RenderResult => { +): [RenderResult, jest.SpyInstance] => { const store = createStore(rootReducer, state); + const dispatch = jest.spyOn(store, 'dispatch'); const i18n = new I18nManager({ locale: 'en' }); - return render( + const result = render( {component} , ); + + return [result, dispatch]; };