From 047acd84ca9041899ffc9403a42734966e28b7f3 Mon Sep 17 00:00:00 2001 From: vashjs Date: Mon, 16 Oct 2023 09:32:46 +0100 Subject: [PATCH] update tests | remove unused reactItl.mock.js | update reactIntl.mock.js --- .../BulkEditLogs/BulkEditLogs.test.js | 9 +++-- test/jest/__mock__/reactIntl.mock.js | 21 +++++++----- test/jest/__mock__/reactItl.mock.js | 33 ------------------- 3 files changed, 18 insertions(+), 45 deletions(-) delete mode 100644 test/jest/__mock__/reactItl.mock.js diff --git a/src/components/BulkEditLogs/BulkEditLogs.test.js b/src/components/BulkEditLogs/BulkEditLogs.test.js index 1ace674c..b2081165 100644 --- a/src/components/BulkEditLogs/BulkEditLogs.test.js +++ b/src/components/BulkEditLogs/BulkEditLogs.test.js @@ -3,6 +3,7 @@ import { render, screen } from '@testing-library/react'; import { MemoryRouter } from 'react-router-dom'; import '../../../test/jest/__mock__'; +import { IntlProvider } from 'react-intl'; import { bulkEditLogsData } from '../../../test/jest/__mock__/fakeData'; import { LOGS_COLUMNS } from '../../constants'; @@ -20,9 +21,11 @@ jest.mock('../../hooks/api', () => ({ const renderBulkEditLogs = () => { render( - - - , + + + + , + ); }; diff --git a/test/jest/__mock__/reactIntl.mock.js b/test/jest/__mock__/reactIntl.mock.js index 6cc49b7c..51220b70 100644 --- a/test/jest/__mock__/reactIntl.mock.js +++ b/test/jest/__mock__/reactIntl.mock.js @@ -9,6 +9,16 @@ jest.mock('react-intl', () => { formatNumber: value => value, }; + const sharedMockFn = jest.fn(({ + value, children, + }) => { + if (children) { + return children([value]); + } + + return value; + }); + return { ...jest.requireActual('react-intl'), FormattedMessage: jest.fn(({ @@ -20,15 +30,8 @@ jest.mock('react-intl', () => { return id; }), - FormattedTime: jest.fn(({ - value, children, - }) => { - if (children) { - return children([value]); - } - - return value; - }), + FormattedTime: sharedMockFn, + FormattedNumber: sharedMockFn, useIntl: () => intl, injectIntl: Component => props => ( { - const intl = { - formatMessage: ({ id }) => id, - formatNumber: (value) => value - }; - - return { - ...jest.requireActual('react-intl'), - FormattedMessage: jest.fn(({ id, values, children }) => { - if (children) { - return children([id]); - } - - const valuesString = values ? (`-${JSON.stringify(values)}`) : ''; - - return `${id}${valuesString}`; - }), - FormattedTime: jest.fn(({ value, children }) => { - if (children) { - return children([value]); - } - - return value; - }), - FormattedNumber: jest.fn((value) => { - return value; - }), - useIntl: () => intl, - injectIntl: (Component) => (props) => , - }; -});