@@ -20,7 +20,7 @@ public class ReactComponentTest
2020 public void RenderHtmlShouldThrowExceptionIfComponentDoesNotExist ( )
2121 {
2222 var environment = new Mock < IReactEnvironment > ( ) ;
23- environment . Setup ( x => x . HasVariable ( " Foo") ) . Returns ( false ) ;
23+ environment . Setup ( x => x . Execute < bool > ( "typeof Foo !== 'undefined' ") ) . Returns ( false ) ;
2424 var component = new ReactComponent ( environment . Object , "Foo" , "container" ) ;
2525
2626 Assert . Throws < ReactInvalidComponentException > ( ( ) =>
@@ -33,7 +33,7 @@ public void RenderHtmlShouldThrowExceptionIfComponentDoesNotExist()
3333 public void RenderHtmlShouldCallRenderComponent ( )
3434 {
3535 var environment = new Mock < IReactEnvironment > ( ) ;
36- environment . Setup ( x => x . HasVariable ( " Foo") ) . Returns ( true ) ;
36+ environment . Setup ( x => x . Execute < bool > ( "typeof Foo !== 'undefined' ") ) . Returns ( true ) ;
3737
3838 var component = new ReactComponent ( environment . Object , "Foo" , "container" )
3939 {
@@ -48,7 +48,7 @@ public void RenderHtmlShouldCallRenderComponent()
4848 public void RenderHtmlShouldWrapComponentInDiv ( )
4949 {
5050 var environment = new Mock < IReactEnvironment > ( ) ;
51- environment . Setup ( x => x . HasVariable ( " Foo") ) . Returns ( true ) ;
51+ environment . Setup ( x => x . Execute < bool > ( "typeof Foo !== 'undefined' ") ) . Returns ( true ) ;
5252 environment . Setup ( x => x . Execute < string > ( @"React.renderComponentToString(Foo({""hello"":""World""}))" ) )
5353 . Returns ( "[HTML]" ) ;
5454
@@ -77,5 +77,25 @@ public void RenderJavaScriptShouldCallRenderComponent()
7777 result
7878 ) ;
7979 }
80+
81+ [ TestCase ( "Foo" , true ) ]
82+ [ TestCase ( "Foo.Bar" , true ) ]
83+ [ TestCase ( "Foo.Bar.Baz" , true ) ]
84+ [ TestCase ( "alert()" , false ) ]
85+ [ TestCase ( "Foo.alert()" , false ) ]
86+ [ TestCase ( "lol what" , false ) ]
87+ public void TestEnsureComponentNameValid ( string input , bool expected )
88+ {
89+ var isValid = true ;
90+ try
91+ {
92+ ReactComponent . EnsureComponentNameValid ( input ) ;
93+ }
94+ catch ( ReactInvalidComponentException )
95+ {
96+ isValid = false ;
97+ }
98+ Assert . AreEqual ( expected , isValid ) ;
99+ }
80100 }
81101}
0 commit comments