This repository was archived by the owner on Oct 19, 2018. It is now read-only.
File tree 3 files changed +42
-20
lines changed
3 files changed +42
-20
lines changed Original file line number Diff line number Diff line change
1
+ module React
2
+ module Test
3
+ class Utils
4
+ `var ReactTestUtils = React.addons.TestUtils`
5
+
6
+ def self . render_into_document ( element , options = { } )
7
+ raise "You should pass a valid React::Element" unless React . is_valid_element ( element )
8
+ native_instance = `ReactTestUtils.renderIntoDocument(#{ element . to_n } )`
9
+
10
+ if `#{ native_instance } ._getOpalInstance !== undefined`
11
+ `#{ native_instance } ._getOpalInstance()`
12
+ else
13
+ native_instance
14
+ end
15
+ end
16
+
17
+ def self . simulate ( event , element )
18
+ Simulate . new . click ( element )
19
+ end
20
+
21
+ class Simulate
22
+ include Native
23
+ def initialize
24
+ super ( `ReactTestUtils.Simulate` )
25
+ end
26
+
27
+ def click ( component_instance )
28
+ `#{ @native } ['click']` . call ( component_instance . dom_node , { } )
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
Original file line number Diff line number Diff line change 1
1
require 'spec_helper'
2
2
3
3
if opal?
4
- module React
5
- module Test
6
- class Utils
7
- def self . simulate ( event , element )
8
- Simulate . new . click ( element )
9
- end
10
-
11
- class Simulate
12
- include Native
13
- def initialize
14
- super ( `React.addons.TestUtils.Simulate` )
15
- end
16
-
17
- def click ( component_instance )
18
- `#{ @native } ['click']` . call ( component_instance . dom_node , { } )
19
- end
20
- end
21
- end
22
- end
23
- end
24
4
RSpec . describe React ::Test ::Utils do
25
5
it 'simulates' do
26
6
stub_const 'Foo' , Class . new
@@ -41,5 +21,13 @@ def render
41
21
expect_any_instance_of ( Foo ) . to receive ( :click )
42
22
described_class . simulate ( :click , instance )
43
23
end
24
+
25
+ describe "render_into_document" do
26
+ it "works with native element" do
27
+ expect {
28
+ described_class . render_into_document ( React . create_element ( 'div' ) )
29
+ } . to_not raise_error
30
+ end
31
+ end
44
32
end
45
33
end
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ def ruby?
18
18
require 'react/react-source'
19
19
require 'hyper-react'
20
20
require 'react/test/rspec'
21
+ require 'react/test/utils'
21
22
22
23
require File . expand_path ( '../support/react/spec_helpers' , __FILE__ )
23
24
You can’t perform that action at this time.
0 commit comments