react-component-snapshot 0.0.0 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +14 -2
- package/src/index.mjs +18 -6
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-component-snapshot",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Transform a React component to match its snapshot in Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -32,13 +32,25 @@
|
|
|
32
32
|
"debug": "^4.4.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
+
"@babel/core": "^7.26.10",
|
|
36
|
+
"@babel/eslint-parser": "^7.26.10",
|
|
37
|
+
"@babel/preset-env": "^7.26.9",
|
|
38
|
+
"@babel/preset-react": "^7.26.3",
|
|
35
39
|
"@sequencemedia/eslint-config-standard": "^0.2.43",
|
|
36
40
|
"@sequencemedia/eslint-config-typescript": "^0.1.62",
|
|
41
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
42
|
+
"@testing-library/react": "^16.2.0",
|
|
37
43
|
"@types/debug": "^4.1.12",
|
|
38
|
-
"@types/
|
|
44
|
+
"@types/jest": "^29.5.14",
|
|
45
|
+
"@types/prop-types": "^15.7.14",
|
|
46
|
+
"@types/react": "^19.0.11",
|
|
39
47
|
"@typescript-eslint/parser": "^8.26.1",
|
|
48
|
+
"core-js": "^3.41.0",
|
|
40
49
|
"eslint": "^9.22.0",
|
|
50
|
+
"eslint-plugin-react": "^7.37.4",
|
|
41
51
|
"globals": "^16.0.0",
|
|
52
|
+
"jest": "^29.7.0",
|
|
53
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
42
54
|
"react": "19.0.0"
|
|
43
55
|
},
|
|
44
56
|
"imports": {
|
package/src/index.mjs
CHANGED
|
@@ -47,8 +47,8 @@ export function getReactPropsKey (stateNode) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
50
|
+
* @param {Element | Text | React.Component<any, any, any>} stateNode
|
|
51
|
+
* @returns {Record<PropertyKey, unknown> | null}
|
|
52
52
|
*/
|
|
53
53
|
export function getStateNodeFiber (stateNode) {
|
|
54
54
|
const key = getReactFiberKey(stateNode)
|
|
@@ -65,8 +65,8 @@ export function getStateNodeFiber (stateNode) {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
68
|
+
* @param {React.Component<any, any, any> | Element | Text} stateNode
|
|
69
|
+
* @returns {Record<PropertyKey, unknown> | null}
|
|
70
70
|
*/
|
|
71
71
|
export function getStateNodeProps (stateNode) {
|
|
72
72
|
const key = getReactPropsKey(stateNode)
|
|
@@ -82,6 +82,18 @@ export function getStateNodeProps (stateNode) {
|
|
|
82
82
|
return null
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
/**
|
|
86
|
+
* @param {{ container: { firstElementChild: Element | null } }} component
|
|
87
|
+
* @returns {Element | null}
|
|
88
|
+
*/
|
|
89
|
+
export function getComponentElement ({
|
|
90
|
+
container: {
|
|
91
|
+
firstElementChild: element
|
|
92
|
+
}
|
|
93
|
+
}) {
|
|
94
|
+
return element
|
|
95
|
+
}
|
|
96
|
+
|
|
85
97
|
/**
|
|
86
98
|
* @param {Element} element
|
|
87
99
|
* @returns {FiberNode | null}
|
|
@@ -220,8 +232,8 @@ function transform (fiberNode) {
|
|
|
220
232
|
}
|
|
221
233
|
|
|
222
234
|
/**
|
|
223
|
-
*
|
|
224
|
-
*
|
|
235
|
+
* @param {Element | null | undefined} element
|
|
236
|
+
* @returns {Record<PropertyKey, unknown> | null}
|
|
225
237
|
*/
|
|
226
238
|
export default function snapshotOf (element) {
|
|
227
239
|
if (element instanceof HTMLElement) {
|