Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit f3953d0

Browse files
committed
allow react test so setup rspec
1 parent a5771b3 commit f3953d0

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

lib/react/test/rspec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'react/test/dsl'
2+
require 'react/test/matchers/render_html_matcher'
3+
4+
RSpec.configure do |config|
5+
config.include React::Test::DSL, type: :component
6+
config.include React::Test::Matchers, type: :component
7+
8+
config.after do
9+
React::Test.reset_session!
10+
end
11+
12+
config.before do
13+
# nothing yet
14+
end
15+
end

spec/react/test/rspec_spec.rb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
require 'spec_helper'
2+
3+
if 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(
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 commit comments

Comments
 (0)