1
1
import React , { Fragment } from 'react' ;
2
2
import parseReactElement from './parseReactElement' ;
3
+
3
4
const options = { } ;
5
+
4
6
describe ( 'parseReactElement' , ( ) => {
5
7
it ( 'should parse a react element with a string as children' , ( ) => {
6
8
expect ( parseReactElement ( < h1 > Hello world</ h1 > , options ) ) . toEqual ( {
@@ -16,6 +18,7 @@ describe('parseReactElement', () => {
16
18
] ,
17
19
} ) ;
18
20
} ) ;
21
+
19
22
it ( 'should filter empty childrens' , ( ) => {
20
23
expect (
21
24
parseReactElement (
@@ -46,6 +49,7 @@ describe('parseReactElement', () => {
46
49
] ,
47
50
} ) ;
48
51
} ) ;
52
+
49
53
it ( 'should parse a single depth react element' , ( ) => {
50
54
expect ( parseReactElement ( < aaa foo = "41" /> , options ) ) . toEqual ( {
51
55
type : 'ReactElement' ,
@@ -57,6 +61,7 @@ describe('parseReactElement', () => {
57
61
childrens : [ ] ,
58
62
} ) ;
59
63
} ) ;
64
+
60
65
it ( 'should parse a react element with an object as props' , ( ) => {
61
66
expect (
62
67
parseReactElement (
@@ -85,6 +90,7 @@ describe('parseReactElement', () => {
85
90
childrens : [ ] ,
86
91
} ) ;
87
92
} ) ;
93
+
88
94
it ( 'should parse a react element with another react element as props' , ( ) => {
89
95
expect ( parseReactElement ( < div a = { < span b = "42" /> } /> , options ) ) . toEqual ( {
90
96
type : 'ReactElement' ,
@@ -96,13 +102,14 @@ describe('parseReactElement', () => {
96
102
childrens : [ ] ,
97
103
} ) ;
98
104
} ) ;
105
+
99
106
it ( 'should parse the react element defaultProps' , ( ) => {
100
107
const Foo = ( ) => { } ;
101
-
102
108
Foo . defaultProps = {
103
109
bar : 'Hello Bar!' ,
104
110
baz : 'Hello Baz!' ,
105
111
} ;
112
+
106
113
expect (
107
114
parseReactElement ( < Foo foo = "Hello Foo!" bar = "Hello world!" /> , options )
108
115
) . toEqual ( {
@@ -120,6 +127,7 @@ describe('parseReactElement', () => {
120
127
childrens : [ ] ,
121
128
} ) ;
122
129
} ) ;
130
+
123
131
it ( 'should extract the component key' , ( ) => {
124
132
expect ( parseReactElement ( < div key = "foo-1" /> , options ) ) . toEqual ( {
125
133
type : 'ReactElement' ,
@@ -131,6 +139,7 @@ describe('parseReactElement', () => {
131
139
childrens : [ ] ,
132
140
} ) ;
133
141
} ) ;
142
+
134
143
it ( 'should extract the component ref' , ( ) => {
135
144
const refFn = ( ) => 'foo' ;
136
145
@@ -143,6 +152,7 @@ describe('parseReactElement', () => {
143
152
} ,
144
153
childrens : [ ] ,
145
154
} ) ;
155
+
146
156
// eslint-disable-next-line react/no-string-refs
147
157
expect ( parseReactElement ( < div ref = "foo" /> , options ) ) . toEqual ( {
148
158
type : 'ReactElement' ,
@@ -154,6 +164,7 @@ describe('parseReactElement', () => {
154
164
childrens : [ ] ,
155
165
} ) ;
156
166
} ) ;
167
+
157
168
it ( 'should parse a react fragment' , ( ) => {
158
169
expect (
159
170
parseReactElement (
0 commit comments