hyper-react 0.12.7 → 0.99.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +48 -34
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +5 -6
- data/README.md +47 -98
- data/Rakefile +6 -28
- data/hyper-react.gemspec +36 -43
- data/lib/hyper-react.rb +4 -73
- data/lib/react/version.rb +3 -0
- metadata +91 -249
- data/.codeclimate.yml +0 -27
- data/.rubocop.yml +0 -1159
- data/.travis.yml +0 -62
- data/Appraisals +0 -31
- data/CHANGELOG.md +0 -143
- data/LICENSE +0 -19
- data/UPGRADING.md +0 -24
- data/component-name-lookup.md +0 -145
- data/config.ru +0 -26
- data/gemfiles/opal_0.10_react_13.gemfile +0 -15
- data/gemfiles/opal_0.10_react_14.gemfile +0 -15
- data/gemfiles/opal_0.10_react_15.gemfile +0 -15
- data/gemfiles/opal_0.8_react_13.gemfile +0 -15
- data/gemfiles/opal_0.8_react_14.gemfile +0 -15
- data/gemfiles/opal_0.8_react_15.gemfile +0 -15
- data/gemfiles/opal_0.9_react_13.gemfile +0 -15
- data/gemfiles/opal_0.9_react_14.gemfile +0 -15
- data/gemfiles/opal_0.9_react_15.gemfile +0 -15
- data/gemfiles/opal_master_react_15.gemfile +0 -16
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb +0 -3
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/test_application.rb +0 -2
- data/lib/generators/reactive_ruby/test_app/templates/boot.rb.erb +0 -6
- data/lib/generators/reactive_ruby/test_app/templates/script/rails +0 -5
- data/lib/generators/reactive_ruby/test_app/templates/test_application.rb.erb +0 -13
- data/lib/generators/reactive_ruby/test_app/templates/views/components/hello_world.rb +0 -11
- data/lib/generators/reactive_ruby/test_app/templates/views/components/todo.rb +0 -14
- data/lib/generators/reactive_ruby/test_app/templates/views/layouts/test_layout.html.erb +0 -0
- data/lib/generators/reactive_ruby/test_app/test_app_generator.rb +0 -111
- data/lib/rails-helpers/top_level_rails_component.rb +0 -54
- data/lib/react-sources/react-server.js +0 -2
- data/lib/react/api.rb +0 -173
- data/lib/react/callbacks.rb +0 -41
- data/lib/react/children.rb +0 -30
- data/lib/react/component.rb +0 -168
- data/lib/react/component/api.rb +0 -50
- data/lib/react/component/base.rb +0 -13
- data/lib/react/component/class_methods.rb +0 -189
- data/lib/react/component/dsl_instance_methods.rb +0 -23
- data/lib/react/component/params.rb +0 -6
- data/lib/react/component/props_wrapper.rb +0 -78
- data/lib/react/component/should_component_update.rb +0 -94
- data/lib/react/component/tags.rb +0 -129
- data/lib/react/config.rb +0 -5
- data/lib/react/config/client.rb.erb +0 -19
- data/lib/react/config/server.rb +0 -23
- data/lib/react/element.rb +0 -169
- data/lib/react/event.rb +0 -76
- data/lib/react/ext/hash.rb +0 -9
- data/lib/react/ext/opal-jquery/element.rb +0 -26
- data/lib/react/ext/string.rb +0 -8
- data/lib/react/hash.rb +0 -13
- data/lib/react/native_library.rb +0 -87
- data/lib/react/object.rb +0 -15
- data/lib/react/react-source-browser.rb +0 -3
- data/lib/react/react-source-server.rb +0 -3
- data/lib/react/react-source.rb +0 -20
- data/lib/react/ref_callback.rb +0 -31
- data/lib/react/rendering_context.rb +0 -144
- data/lib/react/server.rb +0 -23
- data/lib/react/state_wrapper.rb +0 -23
- data/lib/react/test.rb +0 -16
- data/lib/react/test/dsl.rb +0 -17
- data/lib/react/test/matchers/render_html_matcher.rb +0 -56
- data/lib/react/test/rspec.rb +0 -15
- data/lib/react/test/session.rb +0 -37
- data/lib/react/test/utils.rb +0 -25
- data/lib/react/top_level.rb +0 -118
- data/lib/react/top_level_render.rb +0 -29
- data/lib/react/validator.rb +0 -136
- data/lib/reactive-ruby/component_loader.rb +0 -50
- data/lib/reactive-ruby/isomorphic_helpers.rb +0 -212
- data/lib/reactive-ruby/rails.rb +0 -7
- data/lib/reactive-ruby/rails/component_mount.rb +0 -46
- data/lib/reactive-ruby/rails/controller_helper.rb +0 -15
- data/lib/reactive-ruby/rails/railtie.rb +0 -33
- data/lib/reactive-ruby/serializers.rb +0 -15
- data/lib/reactive-ruby/server_rendering/contextual_renderer.rb +0 -42
- data/lib/reactive-ruby/version.rb +0 -3
- data/lib/reactrb/auto-import.rb +0 -27
- data/lib/reactrb/deep-compare.rb +0 -24
- data/lib/reactrb/new-event-name-convention.rb +0 -11
- data/logo1.png +0 -0
- data/logo2.png +0 -0
- data/logo3.png +0 -0
- data/path_release_steps.md +0 -9
- data/spec/controller_helper_spec.rb +0 -34
- data/spec/index.html.erb +0 -11
- data/spec/react/callbacks_spec.rb +0 -138
- data/spec/react/children_spec.rb +0 -76
- data/spec/react/component/base_spec.rb +0 -32
- data/spec/react/component_spec.rb +0 -884
- data/spec/react/dsl_spec.rb +0 -303
- data/spec/react/element_spec.rb +0 -136
- data/spec/react/event_spec.rb +0 -24
- data/spec/react/native_library_spec.rb +0 -322
- data/spec/react/observable_spec.rb +0 -42
- data/spec/react/opal_jquery_extensions_spec.rb +0 -68
- data/spec/react/param_declaration_spec.rb +0 -269
- data/spec/react/react_spec.rb +0 -215
- data/spec/react/refs_callback_spec.rb +0 -56
- data/spec/react/server_spec.rb +0 -25
- data/spec/react/state_spec.rb +0 -55
- data/spec/react/test/dsl_spec.rb +0 -43
- data/spec/react/test/matchers/render_html_matcher_spec.rb +0 -83
- data/spec/react/test/rspec_spec.rb +0 -62
- data/spec/react/test/session_spec.rb +0 -88
- data/spec/react/test/utils_spec.rb +0 -28
- data/spec/react/top_level_component_spec.rb +0 -101
- data/spec/react/tutorial/tutorial_spec.rb +0 -36
- data/spec/react/validator_spec.rb +0 -124
- data/spec/reactive-ruby/component_loader_spec.rb +0 -77
- data/spec/reactive-ruby/isomorphic_helpers_spec.rb +0 -160
- data/spec/reactive-ruby/rails/asset_pipeline_spec.rb +0 -10
- data/spec/reactive-ruby/rails/component_mount_spec.rb +0 -66
- data/spec/reactive-ruby/server_rendering/contextual_renderer_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -149
- data/spec/support/react/spec_helpers.rb +0 -44
- data/spec/vendor/es5-shim.min.js +0 -6
- data/spec/vendor/jquery-2.2.4.min.js +0 -4
data/spec/react/react_spec.rb
DELETED
@@ -1,215 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
if opal?
|
4
|
-
RSpec.describe React, type: :component do
|
5
|
-
after(:each) do
|
6
|
-
React::API.clear_component_class_cache
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "is_valid_element?" do
|
10
|
-
it "should return true if passed a valid element" do
|
11
|
-
element = React::Element.new(`React.createElement('div')`)
|
12
|
-
expect(React.is_valid_element?(element)).to eq(true)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should return false is passed a non React element" do
|
16
|
-
element = React::Element.new(`{}`)
|
17
|
-
expect(React.is_valid_element?(element)).to eq(false)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "create_element" do
|
22
|
-
it "should create a valid element with only tag" do
|
23
|
-
element = React.create_element('div')
|
24
|
-
expect(React.is_valid_element?(element)).to eq(true)
|
25
|
-
end
|
26
|
-
|
27
|
-
context "with block" do
|
28
|
-
it "should create a valid element with text as only child when block yield String" do
|
29
|
-
element = React.create_element('div') { "lorem ipsum" }
|
30
|
-
expect(React.is_valid_element?(element)).to eq(true)
|
31
|
-
expect(element.props.children).to eq("lorem ipsum")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should create a valid element with children as array when block yield Array of element" do
|
35
|
-
element = React.create_element('div') do
|
36
|
-
[React.create_element('span'), React.create_element('span'), React.create_element('span')]
|
37
|
-
end
|
38
|
-
expect(React.is_valid_element?(element)).to eq(true)
|
39
|
-
expect(element.props.children.length).to eq(3)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should render element with children as array when block yield Array of element" do
|
43
|
-
element = React.create_element('div') do
|
44
|
-
[React.create_element('span'), React.create_element('span'), React.create_element('span')]
|
45
|
-
end
|
46
|
-
dom_node = React::Test::Utils.render_into_document(element)
|
47
|
-
|
48
|
-
expect(`#{dom_node}.children.length`).to eq(3)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "custom element" do
|
53
|
-
before do
|
54
|
-
stub_const 'Foo', Class.new
|
55
|
-
Foo.class_eval do
|
56
|
-
def initialize(native)
|
57
|
-
@native = native
|
58
|
-
end
|
59
|
-
|
60
|
-
def render
|
61
|
-
React.create_element("div") { "lorem" }
|
62
|
-
end
|
63
|
-
|
64
|
-
def props
|
65
|
-
Hash.new(`#@native.props`)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should render element with only one children correctly" do
|
71
|
-
element = React.create_element(Foo) { React.create_element('span') }
|
72
|
-
instance = React::Test::Utils.render_into_document(element)
|
73
|
-
expect(instance.props[:children]).not_to be_a(Array)
|
74
|
-
expect(instance.props[:children][:type]).to eq("span")
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should render element with more than one children correctly" do
|
78
|
-
element = React.create_element(Foo) { [React.create_element('span'), React.create_element('span')] }
|
79
|
-
instance = React::Test::Utils.render_into_document(element)
|
80
|
-
expect(instance.props[:children]).to be_a(Array)
|
81
|
-
expect(instance.props[:children].length).to eq(2)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should create a valid element provided class defined `render`" do
|
85
|
-
element = React.create_element(Foo)
|
86
|
-
expect(React.is_valid_element?(element)).to eq(true)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should allow creating with properties" do
|
90
|
-
element = React.create_element(Foo, foo: "bar")
|
91
|
-
expect(element.props.foo).to eq("bar")
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should raise error if provided class doesn't defined `render`" do
|
95
|
-
expect { React.create_element(Array) }.to raise_error
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should use the same instance for the same ReactComponent" do
|
99
|
-
Foo.class_eval do
|
100
|
-
attr_accessor :a
|
101
|
-
def initialize(n)
|
102
|
-
self.a = 10
|
103
|
-
end
|
104
|
-
|
105
|
-
def component_will_mount
|
106
|
-
self.a = 20
|
107
|
-
end
|
108
|
-
|
109
|
-
def render
|
110
|
-
React.create_element("div") { self.a.to_s }
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
expect(Foo).to render_static_html("<div>20</div>")
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should match the instance cycle to ReactComponent life cycle" do
|
118
|
-
`var count = 0;`
|
119
|
-
|
120
|
-
Foo.class_eval do
|
121
|
-
def initialize(native)
|
122
|
-
`count = count + 1;`
|
123
|
-
end
|
124
|
-
def render
|
125
|
-
React.create_element("div")
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
React::Test::Utils.render_into_document(React.create_element(Foo))
|
130
|
-
React::Test::Utils.render_into_document(React.create_element(Foo))
|
131
|
-
|
132
|
-
expect(`count`).to eq(2)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
describe "create element with properties" do
|
137
|
-
it "should enforce snake-cased property name" do
|
138
|
-
element = React.create_element("div", class_name: "foo")
|
139
|
-
expect(element.props.className).to eq("foo")
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should allow custom property" do
|
143
|
-
element = React.create_element("div", foo: "bar")
|
144
|
-
expect(element.props.foo).to eq("bar")
|
145
|
-
end
|
146
|
-
|
147
|
-
it "should not camel-case custom property" do
|
148
|
-
element = React.create_element("div", foo_bar: "foo")
|
149
|
-
expect(element.props.foo_bar).to eq("foo")
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
describe "class_name helpers (React.addons.classSet)" do
|
154
|
-
it "should transform Hash provided to `class_name` props as string", v13_only: true do
|
155
|
-
classes = {foo: true, bar: false, lorem: true}
|
156
|
-
element = React.create_element("div", class_name: classes)
|
157
|
-
expect(element.props.className).to eq("foo lorem")
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should not alter behavior when passing a string" do
|
161
|
-
element = React.create_element("div", class_name: "foo bar")
|
162
|
-
|
163
|
-
expect(element.props.className).to eq("foo bar")
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
describe "render" do
|
169
|
-
async "should render element to DOM" do
|
170
|
-
div = `document.createElement("div")`
|
171
|
-
React.render(React.create_element('span') { "lorem" }, div) do
|
172
|
-
run_async {
|
173
|
-
expect(`div.children[0].tagName`).to eq("SPAN")
|
174
|
-
expect(`div.textContent`).to eq("lorem")
|
175
|
-
}
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
it "should work without providing a block" do
|
180
|
-
div = `document.createElement("div")`
|
181
|
-
React.render(React.create_element('span') { "lorem" }, div)
|
182
|
-
end
|
183
|
-
|
184
|
-
it "returns the actual ruby instance" do
|
185
|
-
stub_const 'Foo', Class.new
|
186
|
-
Foo.class_eval do
|
187
|
-
def render
|
188
|
-
React.create_element("div") { "lorem" }
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
div = `document.createElement("div")`
|
193
|
-
instance = React.render(React.create_element(Foo), div)
|
194
|
-
expect(instance).to be_a(Foo)
|
195
|
-
end
|
196
|
-
|
197
|
-
it "returns the actual DOM node" do
|
198
|
-
div = `document.createElement("div")`
|
199
|
-
node = React.render(React.create_element('span') { "lorem" }, div)
|
200
|
-
expect(`#{node}.nodeType`).to eq(1)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
describe "unmount_component_at_node" do
|
205
|
-
async "should unmount component at node" do
|
206
|
-
div = `document.createElement("div")`
|
207
|
-
React.render(React.create_element('span') { "lorem" }, div ) do
|
208
|
-
run_async {
|
209
|
-
expect(React.unmount_component_at_node(div)).to eq(true)
|
210
|
-
}
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if opal?
|
4
|
-
|
5
|
-
describe 'Refs callback' do
|
6
|
-
before do
|
7
|
-
stub_const 'Foo', Class.new
|
8
|
-
Foo.class_eval do
|
9
|
-
include React::Component
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
it "is invoked with the actual Ruby instance" do
|
14
|
-
stub_const 'Bar', Class.new
|
15
|
-
Bar.class_eval do
|
16
|
-
include React::Component
|
17
|
-
def render
|
18
|
-
React.create_element('div')
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
Foo.class_eval do
|
23
|
-
def my_bar=(bar)
|
24
|
-
$bar = bar
|
25
|
-
end
|
26
|
-
|
27
|
-
def render
|
28
|
-
React.create_element(Bar, ref: method(:my_bar=).to_proc)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
element = React.create_element(Foo)
|
33
|
-
React::Test::Utils.render_into_document(element)
|
34
|
-
expect($bar).to be_a(Bar)
|
35
|
-
$bar = nil
|
36
|
-
end
|
37
|
-
|
38
|
-
it "is invoked with the actual DOM node" do
|
39
|
-
Foo.class_eval do
|
40
|
-
def my_div=(div)
|
41
|
-
$div = div
|
42
|
-
end
|
43
|
-
|
44
|
-
def render
|
45
|
-
React.create_element('div', ref: method(:my_div=).to_proc)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
element = React.create_element(Foo)
|
50
|
-
React::Test::Utils.render_into_document(element)
|
51
|
-
expect(`#{$div}.nodeType`).to eq(1)
|
52
|
-
$div = nil
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
data/spec/react/server_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
if opal?
|
4
|
-
|
5
|
-
RSpec.describe React::Server do
|
6
|
-
after(:each) do
|
7
|
-
React::API.clear_component_class_cache
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "render_to_string" do
|
11
|
-
it "should render a React.Element to string" do
|
12
|
-
ele = React.create_element('span') { "lorem" }
|
13
|
-
expect(React::Server.render_to_string(ele)).to be_kind_of(String)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "render_to_static_markup" do
|
18
|
-
it "should render a React.Element to static markup" do
|
19
|
-
ele = React.create_element('span') { "lorem" }
|
20
|
-
expect(React::Server.render_to_static_markup(ele)).to eq("<span>lorem</span>")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
data/spec/react/state_spec.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if opal?
|
4
|
-
describe 'React::State' do
|
5
|
-
it "can create dynamically initialized exported states" do
|
6
|
-
stub_const 'Foo', Class.new
|
7
|
-
Foo.class_eval do
|
8
|
-
include React::Component
|
9
|
-
export_state(:foo) { 'bar' }
|
10
|
-
end
|
11
|
-
Hyperloop::Application::Boot.run
|
12
|
-
expect(Foo.foo).to eq('bar')
|
13
|
-
end
|
14
|
-
|
15
|
-
# these will all require async operations and testing to see if things get
|
16
|
-
# re-rendered see spec_helper the "render" test method
|
17
|
-
|
18
|
-
# if Foo.foo is used during rendering then when Foo.foo changes we will
|
19
|
-
# rerender
|
20
|
-
it "sets up observers when exported states are read"
|
21
|
-
|
22
|
-
# React::State.set_state(object, attribute, value) +
|
23
|
-
# React::State.get_state(object, attribute)
|
24
|
-
it "can be accessed outside of react using get/set_state"
|
25
|
-
|
26
|
-
it 'ignores state updates during rendering' do
|
27
|
-
stub_const 'StateTest', Class.new(React::Component::Base)
|
28
|
-
StateTest.class_eval do
|
29
|
-
export_state :boom
|
30
|
-
before_mount do
|
31
|
-
# force boom to be on the observing list during the current rendering cycle
|
32
|
-
StateTest.boom! !StateTest.boom
|
33
|
-
# this is automatically called by after_mount / after_update, but we don't want
|
34
|
-
# to have to setup a complicated async test, so we just force it now.
|
35
|
-
# if we don't do this, then updating boom will have no effect on the first render
|
36
|
-
React::State.update_states_to_observe
|
37
|
-
end
|
38
|
-
def render
|
39
|
-
(StateTest.boom ? "Boom" : "No Boom").tap { StateTest.boom! !StateTest.boom }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
%x{
|
43
|
-
var log = [];
|
44
|
-
var org_warn_console = window.console.warn;
|
45
|
-
var org_error_console = window.console.error;
|
46
|
-
window.console.warn = window.console.error = function(str){log.push(str)}
|
47
|
-
}
|
48
|
-
markup = React::Server.render_to_static_markup(React.create_element(StateTest))
|
49
|
-
`window.console.warn = org_warn_console; window.console.error = org_error_console;`
|
50
|
-
expect(markup).to eq('<span>Boom</span>')
|
51
|
-
expect(StateTest.boom).to be_falsy
|
52
|
-
expect(`log`).to eq([])
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
data/spec/react/test/dsl_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if opal?
|
4
|
-
RSpec.describe React::Test::DSL do
|
5
|
-
describe 'the DSL' do
|
6
|
-
let(:session) { Class.new { include React::Test::DSL }.new }
|
7
|
-
|
8
|
-
before do
|
9
|
-
React::Test.reset_session!
|
10
|
-
|
11
|
-
stub_const 'Greeter', Class.new
|
12
|
-
Greeter.class_eval do
|
13
|
-
include React::Component
|
14
|
-
|
15
|
-
params do
|
16
|
-
optional :message
|
17
|
-
optional :from
|
18
|
-
end
|
19
|
-
|
20
|
-
def render
|
21
|
-
span { "Hello #{params.message}" }
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'is possible to include it in another class' do
|
27
|
-
session.mount(Greeter)
|
28
|
-
expect(session.instance).to be_a(Greeter)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should provide a 'component' shortcut for more expressive tests" do
|
32
|
-
session.component.mount(Greeter)
|
33
|
-
expect(session.component.instance).to be_a(Greeter)
|
34
|
-
end
|
35
|
-
|
36
|
-
React::Test::Session::DSL_METHODS.each do |method|
|
37
|
-
it "responds to all DSL method: #{method}" do
|
38
|
-
expect(session).to respond_to(method)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if opal?
|
4
|
-
describe React::Test::Matchers::RenderHTMLMatcher do
|
5
|
-
let(:component) {
|
6
|
-
Class.new do
|
7
|
-
include React::Component
|
8
|
-
params do
|
9
|
-
optional :string
|
10
|
-
end
|
11
|
-
def render
|
12
|
-
div do
|
13
|
-
span { params.string } if params.string
|
14
|
-
'lorem'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
}
|
19
|
-
let(:expected) { '<div>lorem</div>' }
|
20
|
-
let(:matcher) { described_class.new(expected) }
|
21
|
-
|
22
|
-
describe '#matches?' do
|
23
|
-
it 'is truthy when rendered component html equals expected html' do
|
24
|
-
expect(matcher.matches?(component)).to be_truthy
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'is falsey when rendered component html does not equal expected html' do
|
28
|
-
matcher = described_class.new('foo')
|
29
|
-
expect(matcher.matches?(component)).to be_falsey
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#with_params' do
|
34
|
-
let(:expected) { '<div><span>str</span>lorem</div>' }
|
35
|
-
|
36
|
-
it 'renders the component with the given params' do
|
37
|
-
matcher.with_params(string: 'str')
|
38
|
-
expect(matcher.matches?(component)).to be_truthy
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#failure_message' do
|
43
|
-
let(:expected) { '<div><span>str</span>lorem</div>' }
|
44
|
-
|
45
|
-
it 'includes the name of the component' do
|
46
|
-
stub_const 'Foo', component
|
47
|
-
matcher.matches?(Foo)
|
48
|
-
expect(matcher.failure_message).to match(/expected 'Foo'/)
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'includes the params hash' do
|
52
|
-
matcher.with_params(string: 'bar')
|
53
|
-
matcher.matches?(component)
|
54
|
-
expect(matcher.failure_message).to match(/with params '{"string"=>"bar"}'/)
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'includes the expected html value' do
|
58
|
-
matcher.matches?(component)
|
59
|
-
expect(matcher.failure_message).to match(/to render '#{expected}'/)
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'includes the actual html value' do
|
63
|
-
actual = '<div>lorem<\/div>'
|
64
|
-
matcher.matches?(component)
|
65
|
-
expect(matcher.failure_message).to match(/, but '#{actual}' was rendered/)
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'does not include "to not render"' do
|
69
|
-
matcher.matches?(component)
|
70
|
-
expect(matcher.failure_message).to_not match(/to not render/)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe '#negative_failure_message' do
|
75
|
-
let(:expected) { '<div><span>str</span>lorem</div>' }
|
76
|
-
|
77
|
-
it 'includes "to not render"' do
|
78
|
-
matcher.matches?(component)
|
79
|
-
expect(matcher.negative_failure_message).to match(/to not render/)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|