This repository was archived by the owner on Oct 19, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -94,13 +94,20 @@ def find_name_and_parent(component)
94
94
private
95
95
96
96
def find_component ( name )
97
- scopes = "#{ self . class . name } " . split ( '::' ) . inject ( [ Module ] ) do |nesting , next_const |
97
+ component = lookup_const ( name )
98
+ if component && !component . method_defined? ( :render )
99
+ raise "#{ name } does not appear to be a react component."
100
+ end
101
+ component
102
+ end
103
+
104
+ def lookup_const ( name )
105
+ return nil unless name =~ /^[A-Z]/
106
+ scopes = self . class . name . to_s . split ( '::' ) . inject ( [ Module ] ) do |nesting , next_const |
98
107
nesting + [ nesting . last . const_get ( next_const ) ]
99
108
end . reverse
100
- scope = scopes . detect { |s | s . const_defined? ( name ) } || return
101
- component = scope . const_get ( name )
102
- return component if component . method_defined? ( :render )
103
- raise "#{ name } does not appear to be a react component."
109
+ scope = scopes . detect { |s | s . const_defined? ( name ) }
110
+ scope . const_get ( name ) if scope
104
111
end
105
112
end
106
113
end
Original file line number Diff line number Diff line change @@ -148,6 +148,18 @@ def render
148
148
. to raise_error ( 'Comp does not appear to be a react component.' )
149
149
end
150
150
151
+ it 'raises a method missing error' do
152
+ stub_const 'Foo' , Class . new ( React ::Component ::Base )
153
+ Foo . class_eval do
154
+ backtrace :none
155
+ render do
156
+ _undefined_method
157
+ end
158
+ end
159
+ expect { React . render_to_static_markup ( React . create_element ( Foo ) ) }
160
+ . to raise_error ( NoMethodError )
161
+ end
162
+
151
163
it "will treat the component class name as a first class component name" do
152
164
stub_const 'Mod::Bar' , Class . new
153
165
Mod ::Bar . class_eval do
You can’t perform that action at this time.
0 commit comments