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

Commit 903c942

Browse files
committed
rename instance and native to free up component
1 parent 5a3890a commit 903c942

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

lib/react/test/session.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
module React
22
module Test
33
class Session
4+
DSL_METHODS = %i[mount instance native element update_params
5+
force_update!].freeze
6+
47
def mount(component_klass, params = {})
58
@element = React.create_element(component_klass, params)
6-
component
9+
instance
710
end
811

912
def instance
10-
@instance ||= Native(`React.addons.TestUtils.renderIntoDocument(#{element.to_n})`)
13+
@component ||= `#{native.to_n}._getOpalInstance.apply(#{native})`
1114
end
1215

13-
def element
14-
@element
16+
def native
17+
@native ||= Native(
18+
`React.addons.TestUtils.renderIntoDocument(#{element.to_n})`)
1519
end
1620

17-
def component
18-
@component ||= `#{instance.to_n}._getOpalInstance.apply(#{instance})`
21+
def element
22+
@element
1923
end
2024

2125
def update_params(params)
22-
component.set_props(params)
26+
instance.set_props(params)
2327
end
2428

2529
def force_update!
26-
component.force_update!
30+
instance.force_update!
2731
end
2832
end
2933
end

spec/react/test/session_spec.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ def render
2929
end
3030

3131
it 'optionaly passes params to the component' do
32-
component = subject.mount(Greeter, message: 'world')
33-
expect(component.params.message).to eq('world')
32+
instance = subject.mount(Greeter, message: 'world')
33+
expect(instance.params.message).to eq('world')
3434
end
3535
end
3636

37-
describe '#component' do
37+
describe '#instance' do
3838
it 'returns the instance of the mounted component' do
39-
component = subject.mount(Greeter)
40-
expect(subject.component).to eq(component)
39+
instance = subject.mount(Greeter)
40+
expect(subject.instance).to eq(instance)
4141
end
4242
end
4343

@@ -48,38 +48,38 @@ def render
4848
end
4949
end
5050

51-
describe '#instance' do
51+
describe '#native' do
5252
it 'returns the React native instance of the component' do
53-
component = subject.mount(Greeter)
54-
native = component.instance_variable_get('@native')
55-
expect(subject.instance).to eq(native)
53+
instance = subject.mount(Greeter)
54+
native = instance.instance_variable_get('@native')
55+
expect(subject.native).to eq(native)
5656
end
5757
end
5858

5959
describe '#update_params' do
6060
it 'sends new params to the component' do
61-
component = subject.mount(Greeter, message: 'world')
61+
instance = subject.mount(Greeter, message: 'world')
6262
subject.update_params(message: 'moon')
63-
expect(component.params.message).to eq('moon')
63+
expect(instance.params.message).to eq('moon')
6464
end
6565

6666
it 'leaves unspecified params in tact' do
67-
component = subject.mount(Greeter, message: 'world', from: 'outerspace')
67+
instance = subject.mount(Greeter, message: 'world', from: 'outerspace')
6868
subject.update_params(message: 'moon')
69-
expect(component.params.from).to eq('outerspace')
69+
expect(instance.params.from).to eq('outerspace')
7070
end
7171

7272
it 'causes the component to render' do
73-
component = subject.mount(Greeter, message: 'world')
74-
expect(component).to receive(:render)
73+
instance = subject.mount(Greeter, message: 'world')
74+
expect(instance).to receive(:render)
7575
subject.update_params(message: 'moon')
7676
end
7777
end
7878

7979
describe '#force_update' do
8080
it 'causes the component to render' do
81-
component = subject.mount(Greeter)
82-
expect(component).to receive(:render)
81+
instance = subject.mount(Greeter)
82+
expect(instance).to receive(:render)
8383
subject.force_update!
8484
end
8585
end

0 commit comments

Comments
 (0)