From 3eb8558fc75bbe36a4af2ac9d93a0e084e0e55b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 8 May 2024 11:25:50 +0200 Subject: [PATCH] Fix warning about emotion css-in-js library already loaded during tests The emotion library has a check if global vi or jest is set to detect if it is running in a testing environment. Therefore just an empty vi object for the tests to keep it quiet. --- src/web/components/form/__tests__/multiselect.jsx | 9 +++++---- vite.config.ts | 7 ++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/web/components/form/__tests__/multiselect.jsx b/src/web/components/form/__tests__/multiselect.jsx index 6349051ce2..59df248e71 100644 --- a/src/web/components/form/__tests__/multiselect.jsx +++ b/src/web/components/form/__tests__/multiselect.jsx @@ -18,10 +18,11 @@ import {describe, test, expect, testing} from '@gsa/testing'; -import {render, screen, userEvent} from 'web/utils/testing'; +import {render, screen} from 'web/utils/testing'; import { changeSelectInput, + clickElement, getMultiSelectElement, getSelectElement, getSelectItemElements, @@ -118,7 +119,7 @@ describe('MultiSelect tests', () => { const domItems = getSelectItemElements(); expect(domItems.length).toEqual(2); - await userEvent.click(domItems[1]); + await clickElement(domItems[1]); expect(onChange).toHaveBeenCalledWith(['foo'], undefined); }); @@ -144,7 +145,7 @@ describe('MultiSelect tests', () => { const domItems = getSelectItemElements(); expect(domItems.length).toEqual(2); - await userEvent.click(domItems[0]); + await clickElement(domItems[0]); expect(onChange).toHaveBeenCalledWith(['bar'], 'abc'); }); @@ -235,7 +236,7 @@ describe('MultiSelect tests', () => { expect(selectedItems.length).toEqual(2); const deleteIcon = selectedItems[0].querySelector('button'); - await userEvent.click(deleteIcon); + await clickElement(deleteIcon); expect(onChange).toHaveBeenCalledWith(['foo'], undefined); }); diff --git a/vite.config.ts b/vite.config.ts index 0907b326fa..f1d6c9ce84 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -10,7 +10,12 @@ const projectRootDir = path.resolve(__dirname); // https://vitejs.dev/config/ export default defineConfig({ - define: {global: 'window'}, + define: { + global: 'window', + // avoid "You are loading @emotion/react when it is already loaded" warnings during tests + // https://github.com/emotion-js/emotion/discussions/2795#discussioncomment-7885638 + vi: {}, + }, plugins: [ react({include: /\.(mdx|js|jsx|ts|tsx)$/}), legacy(),