Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 2aa05a9

Browse files
committed
cant find components in anonymous scopes fixed
1 parent 66d29bc commit 2aa05a9

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/react/component/tags.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def find_name_and_parent(component)
8383
private
8484

8585
def find_component(name)
86-
scopes = self.class.name.split('::').inject([Module]) do |nesting, next_const|
86+
scopes = "#{self.class.name}".split('::').inject([Module]) do |nesting, next_const|
8787
nesting + [nesting.last.const_get(next_const)]
8888
end.reverse
8989
scope = scopes.detect { |s| s.const_defined?(name) } || return

spec/react/opal_jquery_extensions_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,20 @@
66
React::API.clear_component_class_cache
77
end
88

9-
it 'renders a top level component using render' do
9+
it 'renders a top level component using render with a block' do
10+
stub_const 'Foo', Class.new(React::Component::Base)
11+
Foo.class_eval do
12+
param :name
13+
def render
14+
"hello #{params.name}"
15+
end
16+
end
17+
test_div = Element.new(:div)
18+
test_div.render { Foo(name: 'fred') }
19+
expect(Element[test_div].find('span').html).to eq('hello fred')
20+
end
21+
22+
it 'renders a top level component using render with a container and params ' do
1023
test_div = Element.new(:div)
1124
test_div.render(:span, id: :render_test_span) { 'hello' }
1225
expect(Element[test_div].find('#render_test_span').html).to eq('hello')

0 commit comments

Comments
 (0)