Skip to content

Commit a1018f9

Browse files
committed
Drop Enzyme's support
1 parent 61fcc80 commit a1018f9

Some content is hidden

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

43 files changed

+34
-1624
lines changed

.changeset/polite-items-cheat.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@emotion/jest': major
3+
---
4+
5+
Drop support for Enzyme

docs/testing.mdx

+1-18
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,9 @@ import { createSerializer } from '@emotion/jest'
3232
expect.addSnapshotSerializer(createSerializer())
3333
```
3434

35-
When using Enzyme, you can add `"@emotion/jest/enzyme-serializer"` instead.
36-
37-
```json
38-
{
39-
"snapshotSerializers": ["@emotion/jest/enzyme-serializer"]
40-
}
41-
```
42-
43-
Or use `expect.addSnapshotSerializer` to add it like this:
44-
45-
```javascript
46-
// also adds the enzyme-to-json serializer
47-
import { createEnzymeSerializer } from '@emotion/jest/enzyme-serializer'
48-
49-
expect.addSnapshotSerializer(createEnzymeSerializer())
50-
```
51-
5235
### Writing a test
5336

54-
Writing a test with `@emotion/jest` involves creating a snapshot from the `react-test-renderer` or `enzyme-to-json`'s resulting JSON.
37+
Writing a test with `@emotion/jest` involves creating a snapshot from the `react-test-renderer`'s resulting JSON.
5538

5639
```jsx
5740
import React from 'react'

package.json

-3
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,6 @@
201201
"bundlesize": "^0.13.2",
202202
"codecov": "^2.3.1",
203203
"cssjanus": "^1.2.0",
204-
"enzyme": "^3.11.0",
205-
"enzyme-adapter-react-16": "^1.15.5",
206-
"enzyme-to-json": "^3.6.1",
207204
"eslint": "^8.57.0",
208205
"eslint-config-prettier": "^9.1.0",
209206
"eslint-config-react": "^1.1.7",

packages/css/test/component-selector.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/next-env'
22
import React from 'react'
33
import styled from '@emotion/styled'
44
import renderer from 'react-test-renderer'

packages/css/test/css.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/next-env'
22
import React from 'react'
33
import renderer from 'react-test-renderer'
44
import { css, flush, sheet } from '@emotion/css'

packages/css/test/cx.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/next-env'
22
import React from 'react'
33
import renderer from 'react-test-renderer'
44
import { css, cx } from '@emotion/css'

packages/css/test/inject-global.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/next-env'
22
import { injectGlobal, sheet, flush, css } from '@emotion/css'
33

44
describe('injectGlobal', () => {

packages/css/test/keyframes.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/next-env'
22
import React from 'react'
33
import renderer from 'react-test-renderer'
44
import { keyframes, flush, css } from '@emotion/css'
@@ -13,17 +13,17 @@ describe('keyframes', () => {
1313
animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
1414
transform: translate3d(0,0,0);
1515
}
16-
16+
1717
40%, 43% {
1818
animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
1919
transform: translate3d(0, -30px, 0);
2020
}
21-
21+
2222
70% {
2323
animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
2424
transform: translate3d(0, -15px, 0);
2525
}
26-
26+
2727
90% {
2828
transform: translate3d(0,-4px,0);
2929
}
@@ -54,7 +54,7 @@ describe('keyframes', () => {
5454
from {
5555
transform: rotate(0deg);
5656
}
57-
57+
5858
to {
5959
transform: rotate(${endingRotation});
6060
}

packages/css/test/label-pattern.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/next-env'
22
import React from 'react'
33
import styled from '@emotion/styled'
44
import renderer from 'react-test-renderer'

packages/css/test/no-babel/index.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/next-env'
22
import React from 'react'
33
import renderer from 'react-test-renderer'
44
import { css } from '@emotion/css'

packages/css/test/no-babel/warnings.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/next-env'
22
import { css } from '@emotion/css'
33

44
console.error = jest.fn()

packages/css/test/selectivity.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/next-env'
22
import { css, sheet, flush } from '@emotion/css'
33

44
describe('css', () => {

packages/css/test/source-map/source-map.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/next-env'
22
import { css, sheet, flush } from '@emotion/css'
33

44
const commentPattern = /\/\*[\s\S]*?\*\//g

packages/css/test/warnings.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/next-env'
22
import { css } from '@emotion/css'
33
import createCss from '@emotion/css/create-instance'
44
import * as React from 'react'

packages/jest/README.md

+1-11
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,7 @@ module.exports = {
2222
}
2323
```
2424

25-
To assist with shallow rendering, there's a custom enzyme snapshot serializer, that includes the `enzyme-to-json` serializer, which is available by importing `@emotion/jest/enzyme-serializer`. If you already have the `enzyme-to-json` serializer added to `snapshotSerializers`, it will need to be removed to allow this to work.
26-
27-
```js
28-
// jest.config.js
29-
module.exports = {
30-
// ... other config
31-
snapshotSerializers: ['@emotion/jest/enzyme-serializer']
32-
}
33-
```
34-
35-
Or you can add the serializer via the `expect.addSnapshotSerializer` method like so: (the example below is with react-test-renderer but @emotion/jest also works with enzyme and react-testing-library)
25+
Or you can add the serializer via the `expect.addSnapshotSerializer` method like so:
3626

3727
```jsx
3828
import React from 'react'

packages/jest/enzyme-serializer/package.json

-5
This file was deleted.

packages/jest/enzyme/package.json

-4
This file was deleted.

packages/jest/package.json

+1-21
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414
"import": "./dist/emotion-jest.cjs.mjs",
1515
"default": "./dist/emotion-jest.cjs.js"
1616
},
17-
"./enzyme": {
18-
"types": {
19-
"import": "./enzyme/dist/emotion-jest-enzyme.cjs.mjs",
20-
"default": "./enzyme/dist/emotion-jest-enzyme.cjs.js"
21-
},
22-
"module": "./enzyme/dist/emotion-jest-enzyme.esm.js",
23-
"import": "./enzyme/dist/emotion-jest-enzyme.cjs.mjs",
24-
"default": "./enzyme/dist/emotion-jest-enzyme.cjs.js"
25-
},
2617
"./serializer": {
2718
"types": {
2819
"import": "./serializer/dist/emotion-jest-serializer.cjs.mjs",
@@ -32,15 +23,6 @@
3223
"import": "./serializer/dist/emotion-jest-serializer.cjs.mjs",
3324
"default": "./serializer/dist/emotion-jest-serializer.cjs.js"
3425
},
35-
"./enzyme-serializer": {
36-
"types": {
37-
"import": "./enzyme-serializer/dist/emotion-jest-enzyme-serializer.cjs.mjs",
38-
"default": "./enzyme-serializer/dist/emotion-jest-enzyme-serializer.cjs.js"
39-
},
40-
"module": "./enzyme-serializer/dist/emotion-jest-enzyme-serializer.esm.js",
41-
"import": "./enzyme-serializer/dist/emotion-jest-enzyme-serializer.cjs.mjs",
42-
"default": "./enzyme-serializer/dist/emotion-jest-enzyme-serializer.cjs.js"
43-
},
4426
"./package.json": "./package.json"
4527
},
4628
"types": "types/index.d.ts",
@@ -104,9 +86,7 @@
10486
"preconstruct": {
10587
"entrypoints": [
10688
"./index.js",
107-
"./serializer.js",
108-
"./enzyme.js",
109-
"./enzyme-serializer.js"
89+
"./serializer.js"
11090
]
11191
}
11292
}

packages/jest/src/create-enzyme-serializer.js

-107
This file was deleted.

packages/jest/src/create-serializer.js

-40
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import prettify from '@emotion/css-prettifier'
22
import { replaceClassNames } from './replace-class-names'
3-
import * as enzymeTickler from './enzyme-tickler'
43
import {
54
getClassNamesFromNodes,
65
isReactElement,
76
isEmotionCssPropElementType,
8-
isEmotionCssPropEnzymeElement,
97
isDOMElement,
108
getStylesFromClassNames,
119
getStyleElements,
@@ -102,49 +100,11 @@ function getLabelsFromClassName(keys, className) {
102100
}).filter(Boolean)
103101
}
104102

105-
function isShallowEnzymeElement(
106-
element /*: any */,
107-
keys /*: string[] */,
108-
labels /*: string[] */
109-
) {
110-
const childClassNames = (element.children || [])
111-
.map(({ props = {} }) => props.className || '')
112-
.filter(Boolean)
113-
114-
return !childClassNames.some(className => {
115-
const childLabels = getLabelsFromClassName(keys, className)
116-
return childLabels.every(childLabel => labels.includes(childLabel))
117-
})
118-
}
119-
120103
const createConvertEmotionElements =
121104
(keys /*: string[]*/) => (node /*: any*/) => {
122105
if (isPrimitive(node)) {
123106
return node
124107
}
125-
if (isEmotionCssPropEnzymeElement(node)) {
126-
const className = enzymeTickler.getTickledClassName(node.props.css)
127-
const labels = getLabelsFromClassName(keys, className || '')
128-
129-
if (isShallowEnzymeElement(node, keys, labels)) {
130-
const emotionType = node.props.__EMOTION_TYPE_PLEASE_DO_NOT_USE__
131-
// emotionType will be a string for DOM elements
132-
const type =
133-
typeof emotionType === 'string'
134-
? emotionType
135-
: emotionType.displayName || emotionType.name || 'Component'
136-
return {
137-
...node,
138-
props: filterEmotionProps({
139-
...node.props,
140-
className
141-
}),
142-
type
143-
}
144-
} else {
145-
return node.children[node.children.length - 1]
146-
}
147-
}
148108
if (isEmotionCssPropElementType(node)) {
149109
return {
150110
...node,

packages/jest/src/enzyme-serializer.d.ts

-1
This file was deleted.

packages/jest/src/enzyme-serializer.js

-2
This file was deleted.

0 commit comments

Comments
 (0)