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 +12
-20
lines changed
Expand file tree Collapse file tree 2 files changed +12
-20
lines changed Original file line number Diff line number Diff line change 11module 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;
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments