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

Commit 75e51fd

Browse files
committed
Fix React::Test::Session
1 parent f5d9be3 commit 75e51fd

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

lib/react/test/session.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
module React
22
module Test
33
class Session
4-
DSL_METHODS = %i[mount instance native update_params html].freeze
5-
6-
attr_reader :native
4+
DSL_METHODS = %i[mount instance update_params html].freeze
75

86
def mount(component_klass, params = {})
97
@element = React.create_element(component_klass, params)
@@ -12,21 +10,20 @@ def mount(component_klass, params = {})
1210

1311
def instance
1412
unless @instance
15-
@native = `React.addons.TestUtils.renderIntoDocument(#{@element.to_n})`
16-
@instance = `#@native._getOpalInstance()`
13+
@container = `document.createElement('div')`
14+
@instance = React.render(@element, @container)
1715
end
1816
@instance
1917
end
2018

21-
def update_params(params)
19+
def update_params(params, &block)
2220
cloned_element = React::Element.new(`React.cloneElement(#{@element.to_n}, #{params.to_n})`)
23-
prev_container = `#{@instance.dom_node}.parentNode`
24-
React.render(cloned_element, prev_container)
21+
React.render(cloned_element, @container, &block)
2522
nil
2623
end
2724

2825
def html
29-
html = `#{@instance.dom_node}.parentNode.innerHTML`
26+
html = `#@container.innerHTML`
3027
%x{
3128
var REGEX_REMOVE_ROOT_IDS = /\s?data-reactroot="[^"]*"/g;
3229
var REGEX_REMOVE_IDS = /\s?data-reactid="[^"]+"/g;

spec/react/test/session_spec.rb

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,19 @@ def render
4141
end
4242
end
4343

44-
describe '#native' do
45-
it 'returns the React native instance of the component' do
46-
instance = subject.mount(Greeter)
47-
native = instance.instance_variable_get('@native')
48-
expect(`#{subject.native} === #{native}`).to eq(true)
49-
end
50-
end
51-
5244
describe '#html' do
5345
it 'returns the component rendered to static html' do
5446
subject.mount(Greeter, message: 'world')
5547
expect(subject.html).to eq('<span>Hello world</span>')
5648
end
5749

58-
it 'returns the updated static html' do
50+
async 'returns the updated static html' do
5951
subject.mount(Greeter)
60-
subject.update_params(message: 'moon')
61-
expect(subject.html).to eq('<span>Hello moon</span>')
52+
subject.update_params(message: 'moon') do
53+
run_async {
54+
expect(subject.html).to eq('<span>Hello moon</span>')
55+
}
56+
end
6257
end
6358
end
6459

0 commit comments

Comments
 (0)