@@ -6,6 +6,8 @@ import ifReact from 'enzyme-adapter-react-helper/build/ifReact';
66
77import ExampleReactComponent from './components/ExampleReactComponent' ;
88import { renderReact } from '..' ;
9+ import { renderReact as renderReactClient } from '../lib/client' ;
10+ import { renderReact as renderReactServer } from '../lib/server' ;
911
1012describe ( 'renderReact' , ( ) => {
1113 let result ;
@@ -40,11 +42,81 @@ describe('renderReact', () => {
4042
4143 assert ( hydrateMethod . calledOnce ) ;
4244
45+ hydrateMethod . restore ( ) ;
46+
4347 delete global . window ;
4448 delete global . document ;
4549
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+
46115 hydrateMethod . restore ( ) ;
47116
117+ delete global . window ;
118+ delete global . document ;
119+
48120 done ( ) ;
49121 } ) ;
50122 } ) ;
@@ -67,16 +139,32 @@ describe('renderReact', () => {
67139 global . document = window . document ;
68140
69141 // Calling it again for the client.
70- renderReact ( 'ExampleReactComponent' , ExampleReactComponent ) ;
142+ renderReactClient ( 'ExampleReactComponent' , ExampleReactComponent ) ;
71143
72144 assert ( renderMethod . calledOnce ) ;
73145
74146 sandbox . restore ( ) ;
75147
148+ renderMethod . restore ( ) ;
149+
76150 delete global . window ;
77151 delete global . document ;
78152
79153 done ( ) ;
80154 } ) ;
81155 } ) ;
82156} ) ;
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