-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathtagged_templates_spec.rb
76 lines (64 loc) · 2.3 KB
/
tagged_templates_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
gem 'minitest'
require 'minitest/autorun'
require 'ruby2js/filter/tagged_templates'
describe Ruby2JS::Filter::TaggedTemplates do
def to_js(string)
_(Ruby2JS.convert(string, eslevel: 2015,
filters: [Ruby2JS::Filter::TaggedTemplates], scope: self).to_s)
end
def to_js_es5(string)
_(Ruby2JS.convert(string,
filters: [Ruby2JS::Filter::TaggedTemplates], scope: self).to_s)
end
def to_js_with_new_tags(string)
_(Ruby2JS.convert(string, eslevel: 2015,
filters: [Ruby2JS::Filter::TaggedTemplates], template_literal_tags: %i(tags work), scope: self).to_s)
end
describe "tagged heredoc" do
it "should return tagged template literal" do
js = to_js( "class Element\ndef render\nhtml <<~HTML\n<div>\#{1 + 3}</div>\nHTML\nend\nend" )
js.must_include 'render() {'
js.must_include 'return html`<div>${1 + 3}</div>`'
end
end
describe "tagged short string" do
it "should return tagged template literal" do
js = to_js( "class Element\ndef self.styles\ncss 'display: block'\nend\nend" )
js.must_include 'static get styles() {'
js.must_include 'return css`display: block`'
end
it "should allow assignment" do
to_js('styles = css("color: green")').
must_include('let styles = css`color: green`')
end
end
describe "available tags" do
it "should be customizable" do
to_js_with_new_tags('value = work("some value")').
must_include('let value = work`some value`')
end
end
describe "autobind" do
it "should not autobind methods" do
to_js('class C; def click(event); end; def render; html "<div @click=\"#{click}\"></div>"; end; end').
must_include('{return html`<div @click="${this.click}"></div>`')
end
end
describe "targets" do
it "should not process unless target is nil" do
to_js('styles = self.css("color: green")').
must_include('let styles = this.css("color: green")')
end
end
describe "es5 fallback" do
it "should fallback to call syntax for es5" do
to_js_es5('styles = css("color: green")').
must_include('var styles = css("color: green")')
end
end
describe Ruby2JS::Filter::DEFAULTS do
it "should include TaggedTemplates" do
_(Ruby2JS::Filter::DEFAULTS).must_include Ruby2JS::Filter::TaggedTemplates
end
end
end