11import React , { Fragment } from 'react' ;
22import parseReactElement from './parseReactElement' ;
3+
34const options = { } ;
5+
46describe ( 'parseReactElement' , ( ) => {
57 it ( 'should parse a react element with a string as children' , ( ) => {
68 expect ( parseReactElement ( < h1 > Hello world</ h1 > , options ) ) . toEqual ( {
@@ -16,6 +18,7 @@ describe('parseReactElement', () => {
1618 ] ,
1719 } ) ;
1820 } ) ;
21+
1922 it ( 'should filter empty childrens' , ( ) => {
2023 expect (
2124 parseReactElement (
@@ -46,6 +49,7 @@ describe('parseReactElement', () => {
4649 ] ,
4750 } ) ;
4851 } ) ;
52+
4953 it ( 'should parse a single depth react element' , ( ) => {
5054 expect ( parseReactElement ( < aaa foo = "41" /> , options ) ) . toEqual ( {
5155 type : 'ReactElement' ,
@@ -57,6 +61,7 @@ describe('parseReactElement', () => {
5761 childrens : [ ] ,
5862 } ) ;
5963 } ) ;
64+
6065 it ( 'should parse a react element with an object as props' , ( ) => {
6166 expect (
6267 parseReactElement (
@@ -85,6 +90,7 @@ describe('parseReactElement', () => {
8590 childrens : [ ] ,
8691 } ) ;
8792 } ) ;
93+
8894 it ( 'should parse a react element with another react element as props' , ( ) => {
8995 expect ( parseReactElement ( < div a = { < span b = "42" /> } /> , options ) ) . toEqual ( {
9096 type : 'ReactElement' ,
@@ -96,13 +102,14 @@ describe('parseReactElement', () => {
96102 childrens : [ ] ,
97103 } ) ;
98104 } ) ;
105+
99106 it ( 'should parse the react element defaultProps' , ( ) => {
100107 const Foo = ( ) => { } ;
101-
102108 Foo . defaultProps = {
103109 bar : 'Hello Bar!' ,
104110 baz : 'Hello Baz!' ,
105111 } ;
112+
106113 expect (
107114 parseReactElement ( < Foo foo = "Hello Foo!" bar = "Hello world!" /> , options )
108115 ) . toEqual ( {
@@ -120,6 +127,7 @@ describe('parseReactElement', () => {
120127 childrens : [ ] ,
121128 } ) ;
122129 } ) ;
130+
123131 it ( 'should extract the component key' , ( ) => {
124132 expect ( parseReactElement ( < div key = "foo-1" /> , options ) ) . toEqual ( {
125133 type : 'ReactElement' ,
@@ -131,6 +139,7 @@ describe('parseReactElement', () => {
131139 childrens : [ ] ,
132140 } ) ;
133141 } ) ;
142+
134143 it ( 'should extract the component ref' , ( ) => {
135144 const refFn = ( ) => 'foo' ;
136145
@@ -143,6 +152,7 @@ describe('parseReactElement', () => {
143152 } ,
144153 childrens : [ ] ,
145154 } ) ;
155+
146156 // eslint-disable-next-line react/no-string-refs
147157 expect ( parseReactElement ( < div ref = "foo" /> , options ) ) . toEqual ( {
148158 type : 'ReactElement' ,
@@ -154,6 +164,7 @@ describe('parseReactElement', () => {
154164 childrens : [ ] ,
155165 } ) ;
156166 } ) ;
167+
157168 it ( 'should parse a react fragment' , ( ) => {
158169 expect (
159170 parseReactElement (
0 commit comments