react-component-name 0.0.1 → 0.0.3
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 +37 -25
- package/package.json +3 -3
- package/src/index.mjs +6 -10
- package/tsconfig.json +0 -14
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# react-component-name
|
|
2
2
|
|
|
3
|
-
Get a React component name from its
|
|
3
|
+
Get a React component name from its `DOM` element
|
|
4
4
|
|
|
5
5
|
_These examples use **Testing Library** but you can also get the component name from any rendered element with `getComponentNameFromElement` or from its `Fiber` node with `getComponentNameFromFiber`_
|
|
6
6
|
|
|
@@ -19,28 +19,40 @@ function Component () {
|
|
|
19
19
|
return <div />
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
22
|
+
describe('`getComponentNameFromRender`', () => {
|
|
23
|
+
it('gets the component name from `render`' () => {
|
|
24
|
+
expect(getComponentNameFromRender(render(
|
|
25
|
+
<Component />
|
|
26
|
+
)))
|
|
27
|
+
.toBe('div')
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe('`getComponentNameFromContainerElement`', () => {
|
|
32
|
+
it('gets the component name from the component container element' () => {
|
|
33
|
+
const {
|
|
34
|
+
container
|
|
35
|
+
} = render(
|
|
36
|
+
<Component />
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
expect(getComponentNameFromContainerElement(container))
|
|
40
|
+
.toBe('div')
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
describe('`getComponentNameFromElement`', () => {
|
|
45
|
+
it('gets the component name from the component element' () => {
|
|
46
|
+
const {
|
|
47
|
+
container: {
|
|
48
|
+
firstElementChild: element
|
|
49
|
+
}
|
|
50
|
+
} = render(
|
|
51
|
+
<Component />
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
expect(getComponentNameFromElement(element))
|
|
55
|
+
.toBe('div')
|
|
56
|
+
})
|
|
57
|
+
})
|
|
46
58
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-component-name",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Get a React component name from Fiber",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"@testing-library/react": "^16.2.0",
|
|
44
44
|
"@types/debug": "^4.1.12",
|
|
45
45
|
"@types/jest": "^29.5.14",
|
|
46
|
-
"@types/react": "^19.0.
|
|
47
|
-
"@types/testing-library__react": "^10.0
|
|
46
|
+
"@types/react": "^19.0.12",
|
|
47
|
+
"@types/testing-library__react": "^10.2.0",
|
|
48
48
|
"@typescript-eslint/parser": "^8.26.1",
|
|
49
49
|
"core-js": "^3.41.0",
|
|
50
50
|
"eslint": "^9.22.0",
|
package/src/index.mjs
CHANGED
|
@@ -68,11 +68,9 @@ export function getElementFromRender (render) {
|
|
|
68
68
|
* @param {RenderType} render
|
|
69
69
|
* @returns {Element}
|
|
70
70
|
*/
|
|
71
|
-
export function getContainerElementFromRender (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
} = render
|
|
75
|
-
|
|
71
|
+
export function getContainerElementFromRender ({
|
|
72
|
+
container: containerElement
|
|
73
|
+
}) {
|
|
76
74
|
return containerElement
|
|
77
75
|
}
|
|
78
76
|
|
|
@@ -80,11 +78,9 @@ export function getContainerElementFromRender (render) {
|
|
|
80
78
|
* @param {Element} containerElement
|
|
81
79
|
* @returns {Element | null}
|
|
82
80
|
*/
|
|
83
|
-
function getElementFromContainerElement (
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
} = containerElement
|
|
87
|
-
|
|
81
|
+
function getElementFromContainerElement ({
|
|
82
|
+
firstElementChild: element = null
|
|
83
|
+
}) {
|
|
88
84
|
return element
|
|
89
85
|
}
|
|
90
86
|
|