Skip to content

Commit

Permalink
Fix warning about emotion css-in-js library already loaded during tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bjoernricks committed May 22, 2024
1 parent 6b898b4 commit 3eb8558
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/web/components/form/__tests__/multiselect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
});
Expand All @@ -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');
});
Expand Down Expand Up @@ -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);
});
Expand Down
7 changes: 6 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 3eb8558

Please sign in to comment.