hyper-react 0.99.6 → 1.0.0.lap21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.codeclimate.yml +27 -0
- data/.gitignore +30 -37
- data/.rubocop.yml +1159 -0
- data/.travis.yml +32 -0
- data/Appraisals +31 -0
- data/CHANGELOG.md +143 -0
- data/DOCS.md +1515 -0
- data/Gemfile +2 -5
- data/LICENSE +19 -0
- data/README.md +5 -33
- data/Rakefile +25 -6
- data/UPGRADING.md +24 -0
- data/component-name-lookup.md +145 -0
- data/dciy.toml +3 -0
- data/dciy_prepare.sh +8 -0
- data/dciy_run.sh +10 -0
- data/hyper-react.gemspec +24 -18
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb +3 -0
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/server_rendering.js +5 -0
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/test_application.rb +2 -0
- data/lib/generators/reactive_ruby/test_app/templates/boot.rb.erb +6 -0
- data/lib/generators/reactive_ruby/test_app/templates/script/rails +5 -0
- data/lib/generators/reactive_ruby/test_app/templates/test_application.rb.erb +13 -0
- data/lib/generators/reactive_ruby/test_app/templates/views/components/hello_world.rb +11 -0
- data/lib/generators/reactive_ruby/test_app/templates/views/components/todo.rb +14 -0
- 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 +117 -0
- data/lib/hyper-react.rb +66 -4
- data/lib/rails-helpers/top_level_rails_component.rb +75 -0
- data/lib/react/api.rb +203 -0
- data/lib/react/callbacks.rb +41 -0
- data/lib/react/children.rb +30 -0
- data/lib/react/component.rb +177 -0
- data/lib/react/component/api.rb +69 -0
- data/lib/react/component/base.rb +13 -0
- data/lib/react/component/class_methods.rb +181 -0
- data/lib/react/component/dsl_instance_methods.rb +23 -0
- data/lib/react/component/params.rb +6 -0
- data/lib/react/component/props_wrapper.rb +78 -0
- data/lib/react/component/should_component_update.rb +99 -0
- data/lib/react/component/tags.rb +108 -0
- data/lib/react/config.rb +5 -0
- data/lib/react/config/client.rb.erb +19 -0
- data/lib/react/config/server.rb +23 -0
- data/lib/react/element.rb +150 -0
- data/lib/react/event.rb +76 -0
- data/lib/react/ext/hash.rb +9 -0
- data/lib/react/ext/opal-jquery/element.rb +26 -0
- data/lib/react/ext/string.rb +8 -0
- data/lib/react/hash.rb +13 -0
- data/lib/react/native_library.rb +87 -0
- data/lib/react/object.rb +15 -0
- data/lib/react/react-source-browser.rb +3 -0
- data/lib/react/react-source-server.rb +3 -0
- data/lib/react/react-source.rb +16 -0
- data/lib/react/ref_callback.rb +31 -0
- data/lib/react/rendering_context.rb +146 -0
- data/lib/react/server.rb +19 -0
- data/lib/react/state_wrapper.rb +23 -0
- data/lib/react/test.rb +16 -0
- data/lib/react/test/dsl.rb +17 -0
- data/lib/react/test/matchers/render_html_matcher.rb +56 -0
- data/lib/react/test/rspec.rb +15 -0
- data/lib/react/test/session.rb +37 -0
- data/lib/react/test/utils.rb +71 -0
- data/lib/react/top_level.rb +110 -0
- data/lib/react/top_level_render.rb +28 -0
- data/lib/react/validator.rb +136 -0
- data/lib/reactive-ruby/component_loader.rb +43 -0
- data/lib/reactive-ruby/isomorphic_helpers.rb +235 -0
- data/lib/reactive-ruby/rails.rb +8 -0
- data/lib/reactive-ruby/rails/component_mount.rb +48 -0
- data/lib/reactive-ruby/rails/controller_helper.rb +14 -0
- data/lib/reactive-ruby/rails/railtie.rb +20 -0
- data/lib/reactive-ruby/serializers.rb +15 -0
- data/lib/reactive-ruby/server_rendering/contextual_renderer.rb +41 -0
- data/lib/reactive-ruby/server_rendering/hyper_asset_container.rb +46 -0
- data/lib/reactive-ruby/version.rb +3 -0
- data/lib/reactrb/auto-import.rb +27 -0
- data/logo1.png +0 -0
- data/logo2.png +0 -0
- data/logo3.png +0 -0
- data/path_release_steps.md +9 -0
- data/spec/controller_helper_spec.rb +35 -0
- data/spec/index.html.erb +11 -0
- data/spec/react/callbacks_spec.rb +142 -0
- data/spec/react/children_spec.rb +132 -0
- data/spec/react/component/base_spec.rb +36 -0
- data/spec/react/component_spec.rb +1073 -0
- data/spec/react/dsl_spec.rb +323 -0
- data/spec/react/element_spec.rb +132 -0
- data/spec/react/event_spec.rb +39 -0
- data/spec/react/native_library_spec.rb +387 -0
- data/spec/react/observable_spec.rb +31 -0
- data/spec/react/opal_jquery_extensions_spec.rb +68 -0
- data/spec/react/param_declaration_spec.rb +253 -0
- data/spec/react/react_spec.rb +278 -0
- data/spec/react/refs_callback_spec.rb +65 -0
- data/spec/react/server_spec.rb +25 -0
- data/spec/react/state_spec.rb +52 -0
- data/spec/react/test/dsl_spec.rb +43 -0
- data/spec/react/test/matchers/render_html_matcher_spec.rb +83 -0
- data/spec/react/test/rspec_spec.rb +62 -0
- data/spec/react/test/session_spec.rb +88 -0
- data/spec/react/test/utils_spec.rb +28 -0
- data/spec/react/top_level_component_spec.rb +103 -0
- data/spec/react/tutorial/tutorial_spec.rb +42 -0
- data/spec/react/validator_spec.rb +134 -0
- data/spec/reactive-ruby/component_loader_spec.rb +74 -0
- data/spec/reactive-ruby/isomorphic_helpers_spec.rb +157 -0
- data/spec/reactive-ruby/rails/asset_pipeline_spec.rb +17 -0
- data/spec/reactive-ruby/rails/component_mount_spec.rb +64 -0
- data/spec/reactive-ruby/server_rendering/contextual_renderer_spec.rb +39 -0
- data/spec/spec_helper.rb +55 -0
- data/spec/test_app/README.md +24 -0
- data/spec/test_app/Rakefile +6 -0
- data/spec/test_app/app/assets/config/manifest.js +3 -0
- data/spec/test_app/app/assets/images/.keep +0 -0
- data/spec/test_app/app/assets/javascripts/application.rb +7 -0
- data/spec/test_app/app/assets/javascripts/cable.js +13 -0
- data/spec/test_app/app/assets/javascripts/channels/.keep +0 -0
- data/spec/test_app/app/assets/javascripts/server_rendering.js +5 -0
- data/spec/test_app/app/assets/stylesheets/application.css +15 -0
- data/spec/test_app/app/channels/application_cable/channel.rb +4 -0
- data/spec/test_app/app/channels/application_cable/connection.rb +4 -0
- data/spec/test_app/app/controllers/application_controller.rb +3 -0
- data/spec/test_app/app/controllers/concerns/.keep +0 -0
- data/spec/test_app/app/helpers/application_helper.rb +2 -0
- data/spec/test_app/app/jobs/application_job.rb +2 -0
- data/spec/test_app/app/mailers/application_mailer.rb +4 -0
- data/spec/test_app/app/models/application_record.rb +3 -0
- data/spec/test_app/app/models/concerns/.keep +0 -0
- data/spec/test_app/app/views/components.rb +11 -0
- data/spec/test_app/app/views/components/hello_world.rb +11 -0
- data/spec/test_app/app/views/components/todo.rb +14 -0
- data/spec/test_app/app/views/layouts/application.html.erb +14 -0
- data/spec/test_app/app/views/layouts/explicit_layout.html.erb +0 -0
- data/spec/test_app/app/views/layouts/mailer.html.erb +13 -0
- data/spec/test_app/app/views/layouts/mailer.text.erb +1 -0
- data/spec/test_app/app/views/layouts/test_layout.html.erb +0 -0
- data/spec/test_app/bin/bundle +3 -0
- data/spec/test_app/bin/rails +4 -0
- data/spec/test_app/bin/rake +4 -0
- data/spec/test_app/bin/setup +38 -0
- data/spec/test_app/bin/update +29 -0
- data/spec/test_app/bin/yarn +11 -0
- data/spec/test_app/config.ru +5 -0
- data/spec/test_app/config/application.rb +45 -0
- data/spec/test_app/config/boot.rb +6 -0
- data/spec/test_app/config/cable.yml +10 -0
- data/spec/test_app/config/database.yml +25 -0
- data/spec/test_app/config/environment.rb +5 -0
- data/spec/test_app/config/environments/development.rb +54 -0
- data/spec/test_app/config/environments/production.rb +91 -0
- data/spec/test_app/config/environments/test.rb +42 -0
- data/spec/test_app/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/test_app/config/initializers/assets.rb +14 -0
- data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_app/config/initializers/cookies_serializer.rb +5 -0
- data/spec/test_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/test_app/config/initializers/inflections.rb +16 -0
- data/spec/test_app/config/initializers/mime_types.rb +4 -0
- data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/test_app/config/locales/en.yml +33 -0
- data/spec/test_app/config/puma.rb +56 -0
- data/spec/test_app/config/routes.rb +3 -0
- data/spec/test_app/config/secrets.yml +32 -0
- data/spec/test_app/config/spring.rb +6 -0
- data/spec/test_app/db/development.sqlite3 +0 -0
- data/spec/test_app/db/schema.rb +15 -0
- data/spec/test_app/db/seeds.rb +7 -0
- data/spec/test_app/db/test.sqlite3 +0 -0
- data/spec/test_app/lib/assets/.keep +0 -0
- data/spec/test_app/log/.keep +0 -0
- data/spec/test_app/package.json +5 -0
- data/spec/test_app/public/404.html +67 -0
- data/spec/test_app/public/422.html +67 -0
- data/spec/test_app/public/500.html +66 -0
- data/spec/test_app/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/test_app/public/apple-touch-icon.png +0 -0
- data/spec/test_app/public/favicon.ico +0 -0
- data/spec/vendor/es5-shim.min.js +7 -0
- data/spec/vendor/jquery-2.2.4.min.js +4 -0
- metadata +401 -61
- data/CODE_OF_CONDUCT.md +0 -49
- data/lib/react/version.rb +0 -3
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'Refs callback', js: true do
|
|
4
|
+
before do
|
|
5
|
+
on_client do
|
|
6
|
+
class Foo
|
|
7
|
+
include React::Component
|
|
8
|
+
def self.bar
|
|
9
|
+
@@bar
|
|
10
|
+
end
|
|
11
|
+
def self.bar=(club)
|
|
12
|
+
@@bar = club
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "is invoked with the actual Ruby instance" do
|
|
19
|
+
expect_evaluate_ruby do
|
|
20
|
+
class Bar
|
|
21
|
+
include React::Component
|
|
22
|
+
def render
|
|
23
|
+
React.create_element('div')
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
Foo.class_eval do
|
|
28
|
+
def my_bar=(bars)
|
|
29
|
+
Foo.bar = bars
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def render
|
|
33
|
+
React.create_element(Bar, ref: method(:my_bar=).to_proc)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
element = React.create_element(Foo)
|
|
38
|
+
React::Test::Utils.render_into_document(element)
|
|
39
|
+
begin
|
|
40
|
+
"#{Foo.bar.class.name}"
|
|
41
|
+
rescue
|
|
42
|
+
"Club"
|
|
43
|
+
end
|
|
44
|
+
end.to eq('Bar')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "is invoked with the actual DOM node" do
|
|
48
|
+
# client_option raise_on_js_errors: :off
|
|
49
|
+
expect_evaluate_ruby do
|
|
50
|
+
Foo.class_eval do
|
|
51
|
+
def my_div=(div)
|
|
52
|
+
Foo.bar = div
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def render
|
|
56
|
+
React.create_element('div', ref: method(:my_div=).to_proc)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
element = React.create_element(Foo)
|
|
61
|
+
React::Test::Utils.render_into_document(element)
|
|
62
|
+
"#{Foo.bar.JS['nodeType']}" # aboids json serialisation errors by using "#{}"
|
|
63
|
+
end.to eq("1")
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe 'React::Server', js: true do
|
|
4
|
+
|
|
5
|
+
describe "render_to_string" do
|
|
6
|
+
it "should render a React.Element to string" do
|
|
7
|
+
client_option render_on: :both
|
|
8
|
+
expect_evaluate_ruby do
|
|
9
|
+
ele = React.create_element('span') { "lorem" }
|
|
10
|
+
React::Server.render_to_string(ele).class.name
|
|
11
|
+
end.to eq("String")
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe "render_to_static_markup" do
|
|
16
|
+
it "should render a React.Element to static markup" do
|
|
17
|
+
client_option render_on: :both
|
|
18
|
+
expect_evaluate_ruby do
|
|
19
|
+
ele = React.create_element('span') { "lorem" }
|
|
20
|
+
React::Server.render_to_static_markup(ele)
|
|
21
|
+
end.to eq("<span>lorem</span>")
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'React::State', js: true do
|
|
4
|
+
it "can create dynamically initialized exported states" do
|
|
5
|
+
expect_evaluate_ruby do
|
|
6
|
+
class Foo
|
|
7
|
+
include React::Component
|
|
8
|
+
export_state(:foo) { 'bar' }
|
|
9
|
+
end
|
|
10
|
+
Hyperloop::Application::Boot.run
|
|
11
|
+
Foo.foo
|
|
12
|
+
end.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
|
+
client_option render_on: :both
|
|
28
|
+
evaluate_ruby do
|
|
29
|
+
class StateTest < React::Component::Base
|
|
30
|
+
export_state :boom
|
|
31
|
+
before_mount do
|
|
32
|
+
# force boom to be on the observing list during the current rendering cycle
|
|
33
|
+
StateTest.boom! !StateTest.boom
|
|
34
|
+
# this is automatically called by after_mount / after_update, but we don't want
|
|
35
|
+
# to have to setup a complicated async test, so we just force it now.
|
|
36
|
+
# if we don't do this, then updating boom will have no effect on the first render
|
|
37
|
+
React::State.update_states_to_observe
|
|
38
|
+
end
|
|
39
|
+
def render
|
|
40
|
+
(StateTest.boom ? "Boom" : "No Boom").tap { StateTest.boom! !StateTest.boom }
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
MARKUP = React::Server.render_to_static_markup(React.create_element(StateTest))
|
|
44
|
+
end
|
|
45
|
+
expect_evaluate_ruby("MARKUP").to eq('<span>Boom</span>')
|
|
46
|
+
expect_evaluate_ruby("StateTest.boom").to be_falsy
|
|
47
|
+
expect(page.driver.browser.manage.logs.get(:browser).reject { |entry|
|
|
48
|
+
entry_s = entry.to_s
|
|
49
|
+
entry_s.include?("Deprecated feature") || entry_s.include?("Mount() on the server. This is a no-op.")
|
|
50
|
+
}.size).to eq(0)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
if RUBY_ENGINE == '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
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
if RUBY_ENGINE == '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
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
if RUBY_ENGINE == 'opal'
|
|
4
|
+
RSpec.describe 'react/test/rspec', type: :component do
|
|
5
|
+
before do
|
|
6
|
+
stub_const 'Greeter', Class.new
|
|
7
|
+
Greeter.class_eval do
|
|
8
|
+
include React::Component
|
|
9
|
+
params do
|
|
10
|
+
optional :message
|
|
11
|
+
optional :from
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def render
|
|
15
|
+
span { "Hello #{params.message}" }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'should include react/test in rspec' do
|
|
21
|
+
comp = mount(Greeter)
|
|
22
|
+
expect(component.instance).to eq(comp)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'includes rspec matchers' do
|
|
26
|
+
expect(Greeter).to render_static_html(
|
|
27
|
+
'<span>Hello world</span>'
|
|
28
|
+
).with_params(message: 'world')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe 'resetting the session' do
|
|
32
|
+
it 'creates an instance of the mounted component in one example' do
|
|
33
|
+
mount(Greeter)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it '...then is not availalbe in the next' do
|
|
37
|
+
expect { component.instance }.to raise_error
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
RSpec.describe 'react/test/rspec', type: :other do
|
|
43
|
+
before do
|
|
44
|
+
stub_const 'Greeter', Class.new
|
|
45
|
+
Greeter.class_eval do
|
|
46
|
+
include React::Component
|
|
47
|
+
params do
|
|
48
|
+
optional :message
|
|
49
|
+
optional :from
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def render
|
|
53
|
+
span { "Hello #{params.message}" }
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'should not include react/test in rspec' do
|
|
59
|
+
expect { mount(Greeter) }.to raise_error
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
if RUBY_ENGINE == 'opal'
|
|
4
|
+
RSpec.describe React::Test::Session do
|
|
5
|
+
subject { described_class.new }
|
|
6
|
+
before do
|
|
7
|
+
stub_const 'Greeter', Class.new
|
|
8
|
+
Greeter.class_eval do
|
|
9
|
+
include React::Component
|
|
10
|
+
|
|
11
|
+
params do
|
|
12
|
+
optional :message
|
|
13
|
+
optional :from
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def render
|
|
17
|
+
span { "Hello #{params.message}" }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe '#mount' do
|
|
23
|
+
it 'returns an instance of the mounted component' do
|
|
24
|
+
expect(subject.mount(Greeter)).to be_a(Greeter)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'actualy mounts the component' do
|
|
28
|
+
expect(subject.mount(Greeter)).to be_mounted
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'optionaly passes params to the component' do
|
|
32
|
+
instance = subject.mount(Greeter, message: 'world')
|
|
33
|
+
expect(instance.params.message).to eq('world')
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe '#instance' do
|
|
38
|
+
it 'returns the instance of the mounted component' do
|
|
39
|
+
instance = subject.mount(Greeter)
|
|
40
|
+
expect(subject.instance).to eq(instance)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe '#html' do
|
|
45
|
+
it 'returns the component rendered to static html' do
|
|
46
|
+
subject.mount(Greeter, message: 'world')
|
|
47
|
+
expect(subject.html).to eq('<span>Hello world</span>')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
async 'returns the updated static html' do
|
|
51
|
+
subject.mount(Greeter)
|
|
52
|
+
subject.update_params(message: 'moon') do
|
|
53
|
+
run_async {
|
|
54
|
+
expect(subject.html).to eq('<span>Hello moon</span>')
|
|
55
|
+
}
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe '#update_params' do
|
|
61
|
+
it 'sends new params to the component' do
|
|
62
|
+
instance = subject.mount(Greeter, message: 'world')
|
|
63
|
+
subject.update_params(message: 'moon')
|
|
64
|
+
expect(instance.params.message).to eq('moon')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'leaves unspecified params in tact' do
|
|
68
|
+
instance = subject.mount(Greeter, message: 'world', from: 'outerspace')
|
|
69
|
+
subject.update_params(message: 'moon')
|
|
70
|
+
expect(instance.params.from).to eq('outerspace')
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'causes the component to render' do
|
|
74
|
+
instance = subject.mount(Greeter, message: 'world')
|
|
75
|
+
expect(instance).to receive(:render)
|
|
76
|
+
subject.update_params(message: 'moon')
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe 'instance#force_update!' do
|
|
81
|
+
it 'causes the component to render' do
|
|
82
|
+
instance = subject.mount(Greeter)
|
|
83
|
+
expect(instance).to receive(:render)
|
|
84
|
+
subject.instance.force_update!
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
if RUBY_ENGINE == 'opal'
|
|
4
|
+
RSpec.describe React::Test::Utils do
|
|
5
|
+
it 'simulates' do
|
|
6
|
+
stub_const 'Foo', Class.new
|
|
7
|
+
Foo.class_eval do
|
|
8
|
+
include React::Component
|
|
9
|
+
|
|
10
|
+
def render
|
|
11
|
+
div { 'Click Me' }.on(:click) { |e| click(e) }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
instance = React::Test::Utils.render_into_document(React.create_element(Foo))
|
|
16
|
+
expect(instance).to receive(:click)
|
|
17
|
+
described_class.simulate(:click, instance.dom_node)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe "render_into_document" do
|
|
21
|
+
it "works with native element" do
|
|
22
|
+
expect {
|
|
23
|
+
described_class.render_into_document(React.create_element('div'))
|
|
24
|
+
}.to_not raise_error
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|