@@ -38,7 +38,7 @@ public void ReactWithInitShouldReturnHtmlAndScript()
3838 component . Setup ( x => x . RenderHtml ( It . IsAny < TextWriter > ( ) , false , false , null , null ) )
3939 . Callback ( ( TextWriter writer , bool renderContainerOnly , bool renderServerOnly , Action < Exception , string , string > exceptionHandler , IRenderFunctions renderFunctions ) => writer . Write ( "HTML" ) ) ;
4040
41- component . Setup ( x => x . RenderJavaScript ( It . IsAny < TextWriter > ( ) , It . IsAny < bool > ( ) ) ) . Callback ( ( TextWriter writer , bool waitForDOMContentLoad ) => writer . Write ( "JS" ) ) ;
41+ component . Setup ( x => x . RenderJavaScript ( It . IsAny < TextWriter > ( ) , It . IsAny < bool > ( ) ) ) . Callback ( ( TextWriter writer , bool waitForDOMContentLoad ) => writer . Write ( waitForDOMContentLoad ? "waiting for page load JS" : "JS" ) ) ;
4242
4343 var environment = ConfigureMockEnvironment ( ) ;
4444 environment . Setup ( x => x . CreateComponent (
@@ -57,11 +57,28 @@ public void ReactWithInitShouldReturnHtmlAndScript()
5757 ) . ToHtmlString ( ) ;
5858
5959 Assert . Equal (
60- "HTML" + System . Environment . NewLine + "<script>JS</script>" ,
60+ "HTML" + System . Environment . NewLine + "<script>waiting for page load JS</script>" ,
6161 result . ToString ( )
6262 ) ;
6363 }
6464
65+ [ Fact ]
66+ public void GetInitJavaScriptReturns ( )
67+ {
68+ var component = new Mock < IReactComponent > ( ) ;
69+
70+ var environment = ConfigureMockEnvironment ( ) ;
71+
72+ environment . Setup ( x => x . GetInitJavaScript ( It . IsAny < TextWriter > ( ) , It . IsAny < bool > ( ) ) ) . Callback ( ( TextWriter writer , bool clientOnly ) => writer . Write ( "JS" ) ) ;
73+
74+ var renderJSResult = HtmlHelperExtensions . ReactInitJavaScript ( htmlHelper : null , clientOnly : false ) ;
75+
76+ Assert . Equal (
77+ "<script>JS</script>" ,
78+ renderJSResult . ToString ( )
79+ ) ;
80+ }
81+
6582 [ Fact ]
6683 public void ScriptNonceIsReturned ( )
6784 {
@@ -77,7 +94,7 @@ public void ScriptNonceIsReturned()
7794 component . Setup ( x => x . RenderHtml ( It . IsAny < TextWriter > ( ) , false , false , null , null ) )
7895 . Callback ( ( TextWriter writer , bool renderContainerOnly , bool renderServerOnly , Action < Exception , string , string > exceptionHandle , IRenderFunctions renderFunctions ) => writer . Write ( "HTML" ) ) . Verifiable ( ) ;
7996
80- component . Setup ( x => x . RenderJavaScript ( It . IsAny < TextWriter > ( ) , It . IsAny < bool > ( ) ) ) . Callback ( ( TextWriter writer , bool waitForDOMContentLoad ) => writer . Write ( "JS" ) ) . Verifiable ( ) ;
97+ component . Setup ( x => x . RenderJavaScript ( It . IsAny < TextWriter > ( ) , It . IsAny < bool > ( ) ) ) . Callback ( ( TextWriter writer , bool waitForDOMContentLoad ) => writer . Write ( waitForDOMContentLoad ? "waiting for page load JS" : "JS" ) ) . Verifiable ( ) ;
8198
8299 var config = new Mock < IReactSiteConfiguration > ( ) ;
83100
@@ -101,7 +118,7 @@ public void ScriptNonceIsReturned()
101118 ) . ToHtmlString ( ) ;
102119
103120 Assert . Equal (
104- "HTML" + System . Environment . NewLine + "<script>JS</script>" ,
121+ "HTML" + System . Environment . NewLine + "<script>waiting for page load JS</script>" ,
105122 result . ToString ( )
106123 ) ;
107124
@@ -116,7 +133,7 @@ public void ScriptNonceIsReturned()
116133 ) . ToHtmlString ( ) ;
117134
118135 Assert . Equal (
119- "HTML" + System . Environment . NewLine + "<script nonce=\" " + nonce + "\" >JS</script>" ,
136+ "HTML" + System . Environment . NewLine + "<script nonce=\" " + nonce + "\" >waiting for page load JS</script>" ,
120137 result . ToString ( )
121138 ) ;
122139 }
0 commit comments