@@ -58,19 +58,68 @@ describe('ReactChildren', () => {
58
58
const portalContainer = document . createElement ( 'div' ) ;
59
59
60
60
const simpleChild = < span key = "simple" /> ;
61
- const portal = ReactDOM . createPortal ( simpleChild , portalContainer ) ;
62
- const instance = < div > { portal } </ div > ;
61
+ const reactPortal = ReactDOM . createPortal ( simpleChild , portalContainer ) ;
63
62
64
- React . Children . forEach ( instance . props . children , callback , context ) ;
65
- expect ( callback ) . toHaveBeenCalledWith ( portal , 0 ) ;
63
+ const parentInstance = < div > { reactPortal } </ div > ;
64
+ React . Children . forEach ( parentInstance . props . children , callback , context ) ;
65
+ expect ( callback ) . toHaveBeenCalledWith ( reactPortal , 0 ) ;
66
66
callback . calls . reset ( ) ;
67
67
const mappedChildren = React . Children . map (
68
- instance . props . children ,
68
+ parentInstance . props . children ,
69
+ callback ,
70
+ context ,
71
+ ) ;
72
+ expect ( callback ) . toHaveBeenCalledWith ( reactPortal , 0 ) ;
73
+ expect ( mappedChildren [ 0 ] ) . toEqual ( reactPortal ) ;
74
+ } ) ;
75
+
76
+ it ( 'should support Call components' , ( ) => {
77
+ const context = { } ;
78
+ const callback = jasmine . createSpy ( ) . and . callFake ( function ( kid , index ) {
79
+ expect ( this ) . toBe ( context ) ;
80
+ return kid ;
81
+ } ) ;
82
+ const ReactCallReturn = require ( 'react-call-return' ) ;
83
+ const reactCall = ReactCallReturn . unstable_createCall (
84
+ < span key = "simple" /> ,
85
+ ( ) => { } ,
86
+ ) ;
87
+
88
+ const parentInstance = < div > { reactCall } </ div > ;
89
+ React . Children . forEach ( parentInstance . props . children , callback , context ) ;
90
+ expect ( callback ) . toHaveBeenCalledWith ( reactCall , 0 ) ;
91
+ callback . calls . reset ( ) ;
92
+ const mappedChildren = React . Children . map (
93
+ parentInstance . props . children ,
94
+ callback ,
95
+ context ,
96
+ ) ;
97
+ expect ( callback ) . toHaveBeenCalledWith ( reactCall , 0 ) ;
98
+ expect ( mappedChildren [ 0 ] ) . toEqual ( reactCall ) ;
99
+ } ) ;
100
+
101
+ it ( 'should support Return components' , ( ) => {
102
+ const context = { } ;
103
+ const callback = jasmine . createSpy ( ) . and . callFake ( function ( kid , index ) {
104
+ expect ( this ) . toBe ( context ) ;
105
+ return kid ;
106
+ } ) ;
107
+ const ReactCallReturn = require ( 'react-call-return' ) ;
108
+ const reactReturn = ReactCallReturn . unstable_createReturn (
109
+ < span key = "simple" /> ,
110
+ ) ;
111
+
112
+ const parentInstance = < div > { reactReturn } </ div > ;
113
+ React . Children . forEach ( parentInstance . props . children , callback , context ) ;
114
+ expect ( callback ) . toHaveBeenCalledWith ( reactReturn , 0 ) ;
115
+ callback . calls . reset ( ) ;
116
+ const mappedChildren = React . Children . map (
117
+ parentInstance . props . children ,
69
118
callback ,
70
119
context ,
71
120
) ;
72
- expect ( callback ) . toHaveBeenCalledWith ( portal , 0 ) ;
73
- expect ( mappedChildren [ 0 ] ) . toEqual ( portal ) ;
121
+ expect ( callback ) . toHaveBeenCalledWith ( reactReturn , 0 ) ;
122
+ expect ( mappedChildren [ 0 ] ) . toEqual ( reactReturn ) ;
74
123
} ) ;
75
124
76
125
it ( 'should treat single arrayless child as being in array' , ( ) => {
0 commit comments