From f5af8448fa3678347d68c3f92ff70257f4dd9075 Mon Sep 17 00:00:00 2001 From: Dmytro-Melnyshyn <77053927+Dmytro-Melnyshyn@users.noreply.github.com> Date: Tue, 28 Mar 2023 09:26:27 -0700 Subject: [PATCH] UIIN-2371: Fixing tests due to changes in eact-virtualized-auto-sizer. (#2087) --- test/jest/__mock__/index.js | 1 + .../jest/__mock__/react-virtualized-auto-sizer.js | 1 + test/jest/helpers/Harness.js | 8 -------- test/jest/helpers/mockOffsetSize.js | 15 --------------- 4 files changed, 2 insertions(+), 23 deletions(-) create mode 100644 test/jest/__mock__/react-virtualized-auto-sizer.js delete mode 100644 test/jest/helpers/mockOffsetSize.js diff --git a/test/jest/__mock__/index.js b/test/jest/__mock__/index.js index be8d0d50f..d998d9a0a 100644 --- a/test/jest/__mock__/index.js +++ b/test/jest/__mock__/index.js @@ -10,3 +10,4 @@ import './InstancePlugin.mock'; import './quickMarc.mock'; import './stripesComponents.mock'; import './reactBeautifulDnd.mock'; +import './react-virtualized-auto-sizer'; diff --git a/test/jest/__mock__/react-virtualized-auto-sizer.js b/test/jest/__mock__/react-virtualized-auto-sizer.js new file mode 100644 index 000000000..b354a5408 --- /dev/null +++ b/test/jest/__mock__/react-virtualized-auto-sizer.js @@ -0,0 +1 @@ +jest.mock('react-virtualized-auto-sizer', () => ({ children }) => children({ height: 500, width: 500 })); diff --git a/test/jest/helpers/Harness.js b/test/jest/helpers/Harness.js index 6e8649f71..9e80ee7fe 100644 --- a/test/jest/helpers/Harness.js +++ b/test/jest/helpers/Harness.js @@ -6,14 +6,10 @@ import { CalloutContext } from '@folio/stripes/core'; import translations from '../../../translations/ui-inventory/en'; import prefixKeys from './prefixKeys'; -import mockOffsetSize from './mockOffsetSize'; const Harness = ({ children, translations: translationsConfig, - shouldMockOffsetSize = true, - width = 500, - height = 500, }) => { const allTranslations = prefixKeys(translations); @@ -21,10 +17,6 @@ const Harness = ({ Object.assign(allTranslations, prefixKeys(tx.translations, tx.prefix)); }); - if (shouldMockOffsetSize) { - mockOffsetSize(width, height); - } - const defaultRichTextElements = ['b', 'i', 'em', 'strong', 'span', 'div', 'p', 'ul', 'ol', 'li', 'code'].reduce((res, Tag) => { res[Tag] = chunks => {chunks}; diff --git a/test/jest/helpers/mockOffsetSize.js b/test/jest/helpers/mockOffsetSize.js deleted file mode 100644 index 068698442..000000000 --- a/test/jest/helpers/mockOffsetSize.js +++ /dev/null @@ -1,15 +0,0 @@ -// Taken from https://github.com/bvaughn/react-virtualized-auto-sizer/blob/master/src/__tests__/AutoSizer.js -// AutoSizer uses offsetWidth and offsetHeight. -// Jest runs in JSDom which doesn't support measurements APIs. -const mockOffsetSize = (width, height) => { - Object.defineProperty(HTMLElement.prototype, 'offsetHeight', { - configurable: true, - value: height, - }); - Object.defineProperty(HTMLElement.prototype, 'offsetWidth', { - configurable: true, - value: width, - }); -}; - -export default mockOffsetSize;