This repository was archived by the owner on Oct 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsession_spec.rb
88 lines (75 loc) · 2.43 KB
/
session_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require 'spec_helper'
if RUBY_ENGINE == 'opal'
RSpec.describe React::Test::Session do
subject { described_class.new }
before do
stub_const 'Greeter', Class.new
Greeter.class_eval do
include React::Component
params do
optional :message
optional :from
end
def render
span { "Hello #{params.message}" }
end
end
end
describe '#mount' do
it 'returns an instance of the mounted component' do
expect(subject.mount(Greeter)).to be_a(Greeter)
end
it 'actualy mounts the component' do
expect(subject.mount(Greeter)).to be_mounted
end
it 'optionaly passes params to the component' do
instance = subject.mount(Greeter, message: 'world')
expect(instance.params.message).to eq('world')
end
end
describe '#instance' do
it 'returns the instance of the mounted component' do
instance = subject.mount(Greeter)
expect(subject.instance).to eq(instance)
end
end
describe '#html' do
it 'returns the component rendered to static html' do
subject.mount(Greeter, message: 'world')
expect(subject.html).to eq('<span>Hello world</span>')
end
async 'returns the updated static html' do
subject.mount(Greeter)
subject.update_params(message: 'moon') do
run_async {
expect(subject.html).to eq('<span>Hello moon</span>')
}
end
end
end
describe '#update_params' do
it 'sends new params to the component' do
instance = subject.mount(Greeter, message: 'world')
subject.update_params(message: 'moon')
expect(instance.params.message).to eq('moon')
end
it 'leaves unspecified params in tact' do
instance = subject.mount(Greeter, message: 'world', from: 'outerspace')
subject.update_params(message: 'moon')
expect(instance.params.from).to eq('outerspace')
end
it 'causes the component to render' do
instance = subject.mount(Greeter, message: 'world')
expect(instance).to receive(:render)
subject.update_params(message: 'moon')
end
end
describe 'instance#force_update!' do
it 'causes the component to render' do
instance = subject.mount(Greeter)
expect(instance).to receive(:render)
subject.instance.force_update!
end
end
end
end