From 0d5dfd5069d5d00862d617e77a4460dcb8d8ab7c Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 22 Aug 2023 15:10:35 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7(front)=20configure=20for=20@testin?= =?UTF-8?q?g-library/jest-dom=20version=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The @testing-library/jest-dom new version has a breaking change. The type must be included in the tscfong file as explain in this issue https://github.com/testing-library/jest-dom/issues/517#issuecomment-1687158454 --- src/frontend/packages/lib_tests/src/imageSnapshot.tsx | 3 +++ src/frontend/packages/lib_tests/src/wrapper.tsx | 1 + src/frontend/packages/marsha-config/jest/testSetup.js | 3 --- src/frontend/packages/marsha-config/tsconfig/tsc-base.json | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/frontend/packages/lib_tests/src/imageSnapshot.tsx b/src/frontend/packages/lib_tests/src/imageSnapshot.tsx index e480722b4f..0e36295eaf 100644 --- a/src/frontend/packages/lib_tests/src/imageSnapshot.tsx +++ b/src/frontend/packages/lib_tests/src/imageSnapshot.tsx @@ -2,6 +2,7 @@ import path from 'path'; import { cleanup, render } from '@testing-library/react'; import { Grommet } from 'grommet'; +import { toMatchImageSnapshot } from 'jest-image-snapshot'; import { GenerateImageOptions, generateImage } from 'jsdom-screenshot'; import { GlobalStyles, theme } from 'lib-common'; import React from 'react'; @@ -9,6 +10,8 @@ import React from 'react'; import { wrapInIntlProvider } from './intl'; import { wrapInRouter } from './router'; +expect.extend({ toMatchImageSnapshot }); + const checkSnapshot = () => { // check if test name contains '[screenshot]' if (!expect.getState().currentTestName?.includes('[screenshot]')) { diff --git a/src/frontend/packages/lib_tests/src/wrapper.tsx b/src/frontend/packages/lib_tests/src/wrapper.tsx index 3de0087a74..b51e45ce92 100644 --- a/src/frontend/packages/lib_tests/src/wrapper.tsx +++ b/src/frontend/packages/lib_tests/src/wrapper.tsx @@ -1,5 +1,6 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { Fragment, PropsWithChildren } from 'react'; +import 'jest-styled-components'; import { RenderOptions, appendUtilsElement } from './render'; diff --git a/src/frontend/packages/marsha-config/jest/testSetup.js b/src/frontend/packages/marsha-config/jest/testSetup.js index 7dbbafc695..3b5256cfff 100644 --- a/src/frontend/packages/marsha-config/jest/testSetup.js +++ b/src/frontend/packages/marsha-config/jest/testSetup.js @@ -5,12 +5,9 @@ import '@testing-library/jest-dom'; // Add TextEncoder & TextDecoder to jsdom import { TextEncoder, TextDecoder } from 'util'; -import { toMatchImageSnapshot } from 'jest-image-snapshot'; import React from 'react'; import ResizeObserver from 'resize-observer-polyfill'; -expect.extend({ toMatchImageSnapshot }); - // see https://github.com/jsdom/jsdom/issues/2524 global.TextEncoder = TextEncoder; global.TextDecoder = TextDecoder; diff --git a/src/frontend/packages/marsha-config/tsconfig/tsc-base.json b/src/frontend/packages/marsha-config/tsconfig/tsc-base.json index d72a9f3a27..a7bba0fcc2 100644 --- a/src/frontend/packages/marsha-config/tsconfig/tsc-base.json +++ b/src/frontend/packages/marsha-config/tsconfig/tsc-base.json @@ -14,7 +14,8 @@ "noUnusedParameters": false, "preserveWatchOutput": true, "skipLibCheck": true, - "strict": true + "strict": true, + "types": ["@testing-library/jest-dom"] }, "exclude": ["node_modules"] }