react-component-snapshot 0.0.8 → 0.0.10
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/package.json +4 -4
- package/src/fiber/index.d.mts +12 -0
- package/src/fiber/index.mjs +12 -5
- package/src/fiber/symbols.mjs +3 -1
- package/src/index.d.mts +21 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-component-snapshot",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "Transform a React component to match its snapshot in Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@babel/eslint-parser": "^7.26.10",
|
|
39
39
|
"@babel/preset-env": "^7.26.9",
|
|
40
40
|
"@babel/preset-react": "^7.26.3",
|
|
41
|
-
"@sequencemedia/eslint-config-standard": "^0.2.
|
|
42
|
-
"@sequencemedia/eslint-config-typescript": "^0.1.
|
|
41
|
+
"@sequencemedia/eslint-config-standard": "^0.2.44",
|
|
42
|
+
"@sequencemedia/eslint-config-typescript": "^0.1.64",
|
|
43
43
|
"@testing-library/jest-dom": "^6.6.3",
|
|
44
44
|
"@testing-library/react": "^16.2.0",
|
|
45
45
|
"@types/debug": "^4.1.12",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@types/react": "^19.0.12",
|
|
48
48
|
"@typescript-eslint/parser": "^8.27.0",
|
|
49
49
|
"core-js": "^3.41.0",
|
|
50
|
-
"eslint": "^9.
|
|
50
|
+
"eslint": "^9.23.0",
|
|
51
51
|
"eslint-plugin-react": "^7.37.4",
|
|
52
52
|
"globals": "^16.0.0",
|
|
53
53
|
"husky": "^9.1.7",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type React from 'react'
|
|
2
|
+
|
|
3
|
+
type FiberNode = ReactComponentSnapshotTypes.FiberNode
|
|
4
|
+
type StateNodeType = Element | Text | React.Component<any, any>
|
|
5
|
+
|
|
6
|
+
export function getStateNodeFiber (stateNode: StateNodeType) : Record<PropertyKey, unknown> | null
|
|
7
|
+
|
|
8
|
+
export function getStateNodeProps (stateNode: StateNodeType): Record<PropertyKey, unknown> | null
|
|
9
|
+
|
|
10
|
+
export function getFiber (element: Element): FiberNode | null
|
|
11
|
+
|
|
12
|
+
export default function getSnapshot (fiberNode: FiberNode): Record<PropertyKey, unknown>
|
package/src/fiber/index.mjs
CHANGED
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
} from 'react-component-name'
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
|
-
|
|
11
|
+
REACT_COMPONENT_FORWARD_REF_TYPE,
|
|
12
|
+
REACT_COMPONENT_SNAPSHOT_TYPE
|
|
12
13
|
} from './symbols.mjs'
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -16,7 +17,7 @@ import {
|
|
|
16
17
|
* @returns {v is object}
|
|
17
18
|
*/
|
|
18
19
|
function isObject (v) {
|
|
19
|
-
return (v || false)
|
|
20
|
+
return typeof (v || false) === 'object' && !Array.isArray(v)
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
/**
|
|
@@ -144,8 +145,14 @@ function getProps (fiberNode) {
|
|
|
144
145
|
Object.fromEntries(
|
|
145
146
|
Object.entries(props)
|
|
146
147
|
.filter(([key]) => key !== 'children')
|
|
147
|
-
.filter(([key
|
|
148
|
-
|
|
148
|
+
.filter(([key]) => key !== 'ref')
|
|
149
|
+
.filter(([key, value]) => { // key is not `ref` but value may be a `ref`
|
|
150
|
+
if (isObject(value)) {
|
|
151
|
+
return !(
|
|
152
|
+
value.$$typeof !== REACT_COMPONENT_FORWARD_REF_TYPE /* forward ref */ ||
|
|
153
|
+
'current' in value /* ref shape */
|
|
154
|
+
)
|
|
155
|
+
}
|
|
149
156
|
return true
|
|
150
157
|
})
|
|
151
158
|
)
|
|
@@ -233,7 +240,7 @@ export default function getSnapshot (fiberNode) {
|
|
|
233
240
|
children
|
|
234
241
|
},
|
|
235
242
|
'$$typeof', {
|
|
236
|
-
value:
|
|
243
|
+
value: REACT_COMPONENT_SNAPSHOT_TYPE
|
|
237
244
|
})
|
|
238
245
|
)
|
|
239
246
|
}
|
package/src/fiber/symbols.mjs
CHANGED
package/src/index.d.mts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RenderResult as RenderType
|
|
3
|
+
} from '@testing-library/react'
|
|
4
|
+
|
|
5
|
+
export function getComponentElement (render: RenderType): Element | null
|
|
6
|
+
|
|
7
|
+
export function getComponentElementFromRender (render: RenderType): Element | null
|
|
8
|
+
|
|
9
|
+
export function getContainerElementFromRender (render: RenderType): Element
|
|
10
|
+
|
|
11
|
+
export function toSnapshotFromRender (render: RenderType): Record<PropertyKey, unknown> | null
|
|
12
|
+
|
|
13
|
+
export function toSnapshotFromContainerElement (containerElement: Element): Record<PropertyKey, unknown> | null
|
|
14
|
+
|
|
15
|
+
export function toSnapshotFromComponentElement (componentElement?: Element | null) : Record<PropertyKey, unknown> | null
|
|
16
|
+
|
|
17
|
+
export function snapshotOf (element?: Element | null): Record<PropertyKey, unknown> | null
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
toSnapshotFromRender as toSnapshot
|
|
21
|
+
}
|