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 1
1
module React
2
2
module Test
3
3
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
7
5
8
6
def mount ( component_klass , params = { } )
9
7
@element = React . create_element ( component_klass , params )
@@ -12,21 +10,20 @@ def mount(component_klass, params = {})
12
10
13
11
def instance
14
12
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 )
17
15
end
18
16
@instance
19
17
end
20
18
21
- def update_params ( params )
19
+ def update_params ( params , & block )
22
20
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 )
25
22
nil
26
23
end
27
24
28
25
def html
29
- html = `#{ @instance . dom_node } .parentNode .innerHTML`
26
+ html = `#@container .innerHTML`
30
27
%x{
31
28
var REGEX_REMOVE_ROOT_IDS = /\s ?data-reactroot="[^"]*"/g;
32
29
var REGEX_REMOVE_IDS = /\s ?data-reactid="[^"]+"/g;
Original file line number Diff line number Diff line change @@ -41,24 +41,19 @@ def render
41
41
end
42
42
end
43
43
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
-
52
44
describe '#html' do
53
45
it 'returns the component rendered to static html' do
54
46
subject . mount ( Greeter , message : 'world' )
55
47
expect ( subject . html ) . to eq ( '<span>Hello world</span>' )
56
48
end
57
49
58
- it 'returns the updated static html' do
50
+ async 'returns the updated static html' do
59
51
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
62
57
end
63
58
end
64
59
You can’t perform that action at this time.
0 commit comments