import { expect } from "chai" ; import "./setup" ; import * as React from "react" ; import ServerRenderer from "../ServerRenderer" ; import { Container } from "../di/Container" ; import { ServerResponse } from "../ServerRenderer" ; import { Cq } from "../references" ; import RootComponentRegistry from "../RootComponentRegistry" ; import { ResourceComponent } from "../component/ResourceComponent" ; import Cache from "../store/Cache" ; describe ( "ServerRenderer" , ( ) => { it ( "should render component" , ( ) => { class Test extends ResourceComponent < any , any , any > { public renderBody ( ) { return ( < span > { this . getResource ( ) . text } < /span>); } } let sling = { subscribe : function ( component , path ) : void { component . changedResource ( path , { text : "hi" } ) ; } } ; let container = new Container ( ( { } as Cq ) ) ; container . register ( "sling" , sling ) ; container . register ( "cache" , new Cache ( ) ) ; let registry = ( { getComponent : function ( resourceType ) : any { return Test ; } } as RootComponentRegistry ) ; let renderer = new ServerRenderer ( registry , container ) ; let response = renderer . renderReactComponent ( "/test" , "/components/test" , "disabled" ) ; expect ( response . html ) . to . equal ( '<span data-reactroot="">hi</span>' ) ; } ) ; it ( "should throw error if component is not found" , ( ) => { let registry = ( { getComponent : function ( resourceType ) : any { return null ; } } as RootComponentRegistry ) ; let renderer = new ServerRenderer ( registry , null ) ; let error = false ; try { renderer . renderReactComponent ( "/test" , "/components/test" , "disabled" ) ; } catch ( e ) { error = true ; } expect ( error ) . to . be . true ; } ) ; } ) ;