11import React from 'react' ;
2+ import ReactDOMServer from "react-dom/server" ;
23import Enzyme , { shallow , mount } from 'enzyme' ;
34import { createStore , combineReducers } from 'redux' ;
45import Adapter from 'enzyme-adapter-react-16' ;
56import { Map } from 'immutable'
67import { LocalizeProvider } from '../src/LocalizeProvider' ;
78import { localizeReducer } from '../src/localize' ;
8- import { getTranslate , getLanguages , initialize } from '../src' ;
9+ import { getTranslate , getLanguages , initialize , withLocalize , Translate } from '../src' ;
910import { defaultTranslateOptions } from '../src/localize' ;
1011
1112Enzyme . configure ( { adapter : new Adapter ( ) } ) ;
@@ -86,4 +87,56 @@ describe('<LocalizeProvider />', () => {
8687 )
8788 } ) . not . toThrow ( ) ;
8889 } ) ;
90+
91+ it ( 'should work with SSR' , ( ) => {
92+ class App extends React . Component {
93+ constructor ( props ) {
94+ super ( props ) ;
95+
96+ this . props . initialize ( {
97+ languages : [
98+ { name : "English" , code : "en" } ,
99+ { name : "French" , code : "fr" }
100+ ] ,
101+ translation : {
102+ hello : [ 'hello' , 'alo' ]
103+ } ,
104+ options : {
105+ defaultLanguage : "en" ,
106+ renderToStaticMarkup : ReactDOMServer . renderToStaticMarkup
107+ }
108+ } ) ;
109+ }
110+
111+ render ( ) {
112+ return (
113+ < div >
114+ < Translate id = "hello" />
115+ </ div >
116+ ) ;
117+ }
118+ }
119+
120+ const LocalizedApp = withLocalize ( App ) ;
121+
122+ const result = ReactDOMServer . renderToString (
123+ < LocalizeProvider initialize = { {
124+ languages : [
125+ { name : "English" , code : "en" } ,
126+ { name : "French" , code : "fr" }
127+ ] ,
128+ translation : {
129+ hello : [ 'hello' , 'alo' ]
130+ } ,
131+ options : {
132+ defaultLanguage : "en" ,
133+ renderToStaticMarkup : ReactDOMServer . renderToStaticMarkup
134+ }
135+ } } >
136+ < LocalizedApp />
137+ </ LocalizeProvider >
138+ ) ;
139+
140+ expect ( result ) . toEqual ( '<div>hello</div>' ) ;
141+ } ) ;
89142} ) ;
0 commit comments