Skip to content

Commit c5ce73c

Browse files
[8.19] Apply @emotion/jest matchers globally (elastic#218114) (elastic#219284)
# Backport This will backport the following commits from `main` to `8.19`: - [Apply `@emotion/jest` matchers globally (elastic#218114)](elastic#218114) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Anton Dosov","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-25T16:24:16Z","message":"Apply `@emotion/jest` matchers globally (elastic#218114)\n\n## Summary\n\nclose https://github.com/elastic/kibana/issues/216459\nfollow-up to https://github.com/elastic/kibana/pull/216489\n\nSince we're migrating to Emotion from SCSS/styled-components, this PR\nglobally aligns the Jest setup by adding '@emotion/jest' matchers.\n\nHowever, the matchers conflict with the styled-components Jest matchers,\nso I had to disable them globally and reapply them in the tests where\nthey were used (either the matchers or styled components snapshot\nserializer) . Tracking issue to clean this up\nhttps://github.com/elastic/issues/219037 when migrated to Emotion","sha":"a5502b076348eea13b1ef32c5c9ebc96574bcbc3","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:SharedUX","backport:version","v9.1.0","v8.19.0"],"title":"Apply `@emotion/jest` matchers globally","number":218114,"url":"https://github.com/elastic/kibana/pull/218114","mergeCommit":{"message":"Apply `@emotion/jest` matchers globally (elastic#218114)\n\n## Summary\n\nclose https://github.com/elastic/kibana/issues/216459\nfollow-up to https://github.com/elastic/kibana/pull/216489\n\nSince we're migrating to Emotion from SCSS/styled-components, this PR\nglobally aligns the Jest setup by adding '@emotion/jest' matchers.\n\nHowever, the matchers conflict with the styled-components Jest matchers,\nso I had to disable them globally and reapply them in the tests where\nthey were used (either the matchers or styled components snapshot\nserializer) . Tracking issue to clean this up\nhttps://github.com/elastic/issues/219037 when migrated to Emotion","sha":"a5502b076348eea13b1ef32c5c9ebc96574bcbc3"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/218114","number":218114,"mergeCommit":{"message":"Apply `@emotion/jest` matchers globally (elastic#218114)\n\n## Summary\n\nclose https://github.com/elastic/kibana/issues/216459\nfollow-up to https://github.com/elastic/kibana/pull/216489\n\nSince we're migrating to Emotion from SCSS/styled-components, this PR\nglobally aligns the Jest setup by adding '@emotion/jest' matchers.\n\nHowever, the matchers conflict with the styled-components Jest matchers,\nso I had to disable them globally and reapply them in the tests where\nthey were used (either the matchers or styled components snapshot\nserializer) . Tracking issue to clean this up\nhttps://github.com/elastic/issues/219037 when migrated to Emotion","sha":"a5502b076348eea13b1ef32c5c9ebc96574bcbc3"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> --------- Co-authored-by: Anton Dosov <[email protected]>
1 parent 606de71 commit c5ce73c

File tree

61 files changed

+103
-66
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+103
-66
lines changed

src/core/packages/chrome/browser-internal/src/ui/header/__snapshots__/collapsible_nav.test.tsx.snap

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/packages/chrome/browser-internal/src/ui/header/__snapshots__/screen_reader_a11y.test.tsx.snap

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/platform/packages/shared/kbn-test/src/jest/setup/emotion.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
import { createSerializer } from '@emotion/jest';
10+
import { createSerializer, matchers } from '@emotion/jest';
1111
import { replaceEmotionPrefix } from '@elastic/eui/lib/test';
1212

13+
// Add the custom matchers provided by '@emotion/jest'
14+
// eslint-disable-next-line no-undef
15+
expect.extend(matchers);
16+
1317
module.exports = createSerializer({
1418
classNameReplacer: replaceEmotionPrefix,
1519
includeStyles: false,

src/platform/packages/shared/kbn-test/src/jest/setup/setup_test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
Global import, so we don't need to remember to import the lib in each file
1212
https://www.npmjs.com/package/jest-styled-components#global-installation
1313
*/
14-
15-
import 'jest-styled-components';
1614
import '@testing-library/jest-dom';
1715

1816
// uses subpath exports

src/platform/packages/shared/response-ops/alerts-table/components/hover_visibility_container.test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
import React from 'react';
1111
import { render, screen } from '@testing-library/react';
1212
import { HoverVisibilityContainer } from './hover_visibility_container';
13-
import { matchers } from '@emotion/jest';
14-
15-
expect.extend(matchers);
1613

1714
describe('HoverVisibilityContainer', () => {
1815
const targetClass1 = 'Component1';

src/platform/packages/shared/shared-ux/button_toolbar/src/popover/popover.test.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
import React from 'react';
1111
import { mountWithIntl } from '@kbn/test-jest-helpers';
12-
import { matchers } from '@emotion/jest';
13-
expect.extend(matchers);
1412

1513
import { ToolbarPopover } from './popover';
1614

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
11
{
22
"extends": "../../../../../../tsconfig.base.json",
33
"compilerOptions": {
4-
"outDir": "target/types",
5-
"types": [
6-
"jest",
7-
"node",
8-
"react",
9-
"@kbn/ambient-ui-types"
10-
]
4+
"outDir": "target/types"
115
},
12-
"include": [
13-
"**/*.ts",
14-
"**/*.tsx",
15-
],
16-
"kbn_references": [
17-
"@kbn/i18n",
18-
"@kbn/test-jest-helpers",
19-
],
20-
"exclude": [
21-
"target/**/*",
22-
]
6+
"include": ["**/*.ts", "**/*.tsx"],
7+
"kbn_references": ["@kbn/i18n", "@kbn/test-jest-helpers"],
8+
"exclude": ["target/**/*"]
239
}

src/platform/plugins/private/vis_types/table/public/components/table_visualization.test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@ import { shallow } from 'enzyme';
2626
import { render } from '@testing-library/react';
2727
import { IInterpreterRenderHandlers } from '@kbn/expressions-plugin/common';
2828
import { coreMock } from '@kbn/core/public/mocks';
29-
import { matchers } from '@emotion/jest';
3029
import { FormattedColumns, TableVisConfig, TableVisData } from '../types';
3130
import TableVisualizationComponent from './table_visualization';
3231
import { useUiState } from '../utils';
3332

34-
expect.extend(matchers);
35-
3633
describe('TableVisualizationComponent', () => {
3734
const coreStartMock = coreMock.createStart();
3835
const handlers = {

src/platform/plugins/shared/chart_expressions/expression_legacy_metric/public/components/__snapshots__/with_auto_scale.test.tsx.snap

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/platform/plugins/shared/discover/public/components/doc_table/components/table_row/table_cell.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import React from 'react';
11+
import 'jest-styled-components';
1112
import { mount } from 'enzyme';
1213
import type { CellProps } from './table_cell';
1314
import { TableCell } from './table_cell';

0 commit comments

Comments
 (0)