@@ -6,6 +6,8 @@ import ifReact from 'enzyme-adapter-react-helper/build/ifReact';
6
6
7
7
import ExampleReactComponent from './components/ExampleReactComponent' ;
8
8
import { renderReact } from '..' ;
9
+ import { renderReact as renderReactClient } from '../lib/client' ;
10
+ import { renderReact as renderReactServer } from '../lib/server' ;
9
11
10
12
describe ( 'renderReact' , ( ) => {
11
13
let result ;
@@ -40,11 +42,81 @@ describe('renderReact', () => {
40
42
41
43
assert ( hydrateMethod . calledOnce ) ;
42
44
45
+ hydrateMethod . restore ( ) ;
46
+
43
47
delete global . window ;
44
48
delete global . document ;
45
49
50
+ done ( ) ;
51
+ } ) ;
52
+ } ) ;
53
+
54
+ it ( 'calls hypernova.client (render method)' , ( done ) => {
55
+ jsdom . env ( result , ( err , window ) => {
56
+ if ( err ) {
57
+ done ( err ) ;
58
+ return ;
59
+ }
60
+
61
+ const sandbox = sinon . createSandbox ( ) ;
62
+ if ( ReactDOM . hydrate ) {
63
+ sandbox . stub ( ReactDOM , 'hydrate' ) . value ( undefined ) ;
64
+ }
65
+
66
+ const renderMethod = sinon . spy ( ReactDOM , 'render' ) ;
67
+
68
+ global . window = window ;
69
+ global . document = window . document ;
70
+
71
+ // Calling it again for the client.
72
+ renderReact ( 'ExampleReactComponent' , ExampleReactComponent ) ;
73
+
74
+ assert ( renderMethod . calledOnce ) ;
75
+
76
+ sandbox . restore ( ) ;
77
+ renderMethod . restore ( ) ;
78
+
79
+ delete global . window ;
80
+ delete global . document ;
81
+
82
+ done ( ) ;
83
+ } ) ;
84
+ } ) ;
85
+ } ) ;
86
+
87
+ describe ( 'renderReact client side endpoint' , ( ) => {
88
+ let result ;
89
+ beforeEach ( ( ) => {
90
+ result = renderReact ( 'ExampleReactComponent' , ExampleReactComponent ) ( { name : 'Desmond' } ) ;
91
+ } ) ;
92
+
93
+ it ( 'exists' , ( ) => {
94
+ assert . isFunction ( renderReactClient ) ;
95
+ assert . equal ( renderReactClient . length , 2 ) ;
96
+ } ) ;
97
+
98
+ ifReact ( '>= 16' , it , it . skip ) ( 'calls hypernova.client (hydrate method)' , ( done ) => {
99
+ jsdom . env ( result , ( err , window ) => {
100
+ if ( err ) {
101
+ done ( err ) ;
102
+ return ;
103
+ }
104
+
105
+ global . window = window ;
106
+ global . document = window . document ;
107
+
108
+ const hydrateMethod = sinon . spy ( ReactDOM , 'hydrate' ) ;
109
+
110
+ // Calling it again for the client.
111
+ renderReactClient ( 'ExampleReactComponent' , ExampleReactComponent ) ;
112
+
113
+ assert ( hydrateMethod . calledOnce ) ;
114
+
46
115
hydrateMethod . restore ( ) ;
47
116
117
+ delete global . window ;
118
+ delete global . document ;
119
+
48
120
done ( ) ;
49
121
} ) ;
50
122
} ) ;
@@ -67,16 +139,32 @@ describe('renderReact', () => {
67
139
global . document = window . document ;
68
140
69
141
// Calling it again for the client.
70
- renderReact ( 'ExampleReactComponent' , ExampleReactComponent ) ;
142
+ renderReactClient ( 'ExampleReactComponent' , ExampleReactComponent ) ;
71
143
72
144
assert ( renderMethod . calledOnce ) ;
73
145
74
146
sandbox . restore ( ) ;
75
147
148
+ renderMethod . restore ( ) ;
149
+
76
150
delete global . window ;
77
151
delete global . document ;
78
152
79
153
done ( ) ;
80
154
} ) ;
81
155
} ) ;
82
156
} ) ;
157
+
158
+ describe ( 'renderReact server side endpoint' , ( ) => {
159
+ it ( 'exists' , ( ) => {
160
+ assert . isFunction ( renderReactServer ) ;
161
+ assert . equal ( renderReactServer . length , 2 ) ;
162
+ } ) ;
163
+
164
+ it ( 'has correct markup on server' , ( ) => {
165
+ const result = renderReactServer ( 'ExampleReactComponent' , ExampleReactComponent ) ( { name : 'Desmond' } ) ;
166
+
167
+ assert . isString ( result ) ;
168
+ assert . match ( result , / H e l l o D e s m o n d / ) ;
169
+ } ) ;
170
+ } ) ;
0 commit comments