From ca8bbd18366eeccc7970427842544c433097c4b0 Mon Sep 17 00:00:00 2001 From: Krzysztof Jelski Date: Thu, 16 Sep 2021 15:08:53 +0200 Subject: [PATCH] Reduce warnings in tests (#6132) * Change i18next from wait to suspense (resolves console warning in app and in tests) * Reduce error and warning output in fast tests --- .../apps-electron/src/main/account-store.spec.ts | 4 ++++ packages/page-accounts/src/modals/Create.spec.tsx | 1 + .../react-components/src/Modal/Modal.spec.tsx | 15 +++++++++++---- .../react-components/src/Popup/Popup.spec.tsx | 11 +++++++++-- packages/react-components/src/i18n/index.ts | 2 +- packages/test-support/src/pagesElements/Table.ts | 5 +++-- 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/packages/apps-electron/src/main/account-store.spec.ts b/packages/apps-electron/src/main/account-store.spec.ts index c7c231e7b1..c3e30e43de 100644 --- a/packages/apps-electron/src/main/account-store.spec.ts +++ b/packages/apps-electron/src/main/account-store.spec.ts @@ -49,10 +49,14 @@ describe('Account store', () => { }); it('get returns null if account does not exist', async () => { + jest.spyOn(console, 'error').mockImplementationOnce(() => { /**/ }); + expect(await accountStore['account-store-get']('1')).toEqual(null); }); it('account disappears from list after it is removed', async () => { + jest.spyOn(console, 'error').mockImplementationOnce(() => { /**/ }); + await accountStore['account-store-set']('1', exampleAccount('a')); await accountStore['account-store-remove']('1'); diff --git a/packages/page-accounts/src/modals/Create.spec.tsx b/packages/page-accounts/src/modals/Create.spec.tsx index fe602b2eb9..aa50ba6b2b 100644 --- a/packages/page-accounts/src/modals/Create.spec.tsx +++ b/packages/page-accounts/src/modals/Create.spec.tsx @@ -64,6 +64,7 @@ describe('Create an account modal', () => { await expectThirdStep(); pressEnterKey(); + await waitForElementToBeRemoved(() => screen.queryByText('Add an account via seed 3/3')); expectCreateAnAccountCall(); }); diff --git a/packages/react-components/src/Modal/Modal.spec.tsx b/packages/react-components/src/Modal/Modal.spec.tsx index eae081e60b..80338b3faa 100644 --- a/packages/react-components/src/Modal/Modal.spec.tsx +++ b/packages/react-components/src/Modal/Modal.spec.tsx @@ -2,13 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 import { fireEvent, render, screen } from '@testing-library/react'; -import React from 'react'; +import React, { Suspense } from 'react'; import { ThemeProvider } from 'styled-components'; import { lightTheme } from '@polkadot/apps/themes'; import { useToggle } from '@polkadot/react-hooks'; import Button from '../Button'; +import i18next from '../i18n'; import Modal from './index'; function TestModal () { @@ -45,13 +46,19 @@ function TestModal () { function renderModal () { return render( - - - + + + + + ); } describe('Modal Component', () => { + beforeAll(async () => { + await i18next.changeLanguage('en'); + }); + it('opens and closes modal', async () => { renderModal(); diff --git a/packages/react-components/src/Popup/Popup.spec.tsx b/packages/react-components/src/Popup/Popup.spec.tsx index a1b88eceeb..465ddba0e3 100644 --- a/packages/react-components/src/Popup/Popup.spec.tsx +++ b/packages/react-components/src/Popup/Popup.spec.tsx @@ -2,9 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 import { fireEvent, render, screen } from '@testing-library/react'; -import React from 'react'; +import React, { Suspense } from 'react'; import { Popup } from '@polkadot/react-components'; +import i18next from '@polkadot/react-components/i18n'; function TestPopup () { return ( @@ -23,11 +24,17 @@ function TestPopup () { function renderPopup () { return render( - + + + ); } describe('Popup Component', () => { + beforeAll(async () => { + await i18next.changeLanguage('en'); + }); + it('opens and closes', async () => { renderPopup(); diff --git a/packages/react-components/src/i18n/index.ts b/packages/react-components/src/i18n/index.ts index 95df940e0c..ad67a01bab 100644 --- a/packages/react-components/src/i18n/index.ts +++ b/packages/react-components/src/i18n/index.ts @@ -73,7 +73,7 @@ i18next ], nsSeparator: false, react: { - wait: true + useSuspense: true }, returnEmptyString: false, returnNull: false diff --git a/packages/test-support/src/pagesElements/Table.ts b/packages/test-support/src/pagesElements/Table.ts index 619d516e84..b0a03f104d 100644 --- a/packages/test-support/src/pagesElements/Table.ts +++ b/packages/test-support/src/pagesElements/Table.ts @@ -20,11 +20,12 @@ export class Table { async assertRowsOrder (balancesExpectedOrder: number[]): Promise { const orderedRows = await this.getRows(); - await Promise.all(orderedRows.map(async (row, index) => { + for (let index = 0; index < orderedRows.length; index++) { + const row = orderedRows[index]; const expectedBalanceTextContent = showBalance(balancesExpectedOrder[index]); expect(await row.getBalanceSummary()).toHaveTextContent(expectedBalanceTextContent); - })); + } } async assertColoring (): Promise {