@@ -20,7 +20,7 @@ public class ReactComponentTest
20
20
public void RenderHtmlShouldThrowExceptionIfComponentDoesNotExist ( )
21
21
{
22
22
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 ) ;
24
24
var component = new ReactComponent ( environment . Object , "Foo" , "container" ) ;
25
25
26
26
Assert . Throws < ReactInvalidComponentException > ( ( ) =>
@@ -33,7 +33,7 @@ public void RenderHtmlShouldThrowExceptionIfComponentDoesNotExist()
33
33
public void RenderHtmlShouldCallRenderComponent ( )
34
34
{
35
35
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 ) ;
37
37
38
38
var component = new ReactComponent ( environment . Object , "Foo" , "container" )
39
39
{
@@ -48,7 +48,7 @@ public void RenderHtmlShouldCallRenderComponent()
48
48
public void RenderHtmlShouldWrapComponentInDiv ( )
49
49
{
50
50
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 ) ;
52
52
environment . Setup ( x => x . Execute < string > ( @"React.renderComponentToString(Foo({""hello"":""World""}))" ) )
53
53
. Returns ( "[HTML]" ) ;
54
54
@@ -77,5 +77,25 @@ public void RenderJavaScriptShouldCallRenderComponent()
77
77
result
78
78
) ;
79
79
}
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
+ }
80
100
}
81
101
}
0 commit comments