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

Commit 7286981

Browse files
committed
include html test session method #106
1 parent d23a98e commit 7286981

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/react/test/session.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module React
22
module Test
33
class Session
44
DSL_METHODS = %i[mount instance native element update_params
5-
force_update!].freeze
5+
force_update! html].freeze
66

77
def mount(component_klass, params = {})
88
@element = React.create_element(component_klass, params)
@@ -29,6 +29,10 @@ def update_params(params)
2929
def force_update!
3030
instance.force_update!
3131
end
32+
33+
def html
34+
React.render_to_static_markup(element)
35+
end
3236
end
3337
end
3438
end

spec/react/test/session_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ def render
5656
end
5757
end
5858

59+
describe '#html' do
60+
it 'returns the component rendered to static html' do
61+
subject.mount(Greeter, message: 'world')
62+
expect(subject.html).to eq('<span>Hello world</span>')
63+
end
64+
end
65+
5966
describe '#update_params' do
6067
it 'sends new params to the component' do
6168
instance = subject.mount(Greeter, message: 'world')

0 commit comments

Comments
 (0)