Skip to content

Commit 96b01e9

Browse files
committed
adds specs and closes #62
1 parent 719642a commit 96b01e9

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

ruby/hyper-component/lib/hyperstack/ext/component/element.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,16 @@ def self.[](selector)
4545
Element.expose :mount_components
4646
end
4747

48+
module Hyperstack
49+
module Internal
50+
module Component
51+
module InstanceMethods
52+
def set_jq(var)
53+
->(val) { set(var).call(JQ[val]) }
54+
end
55+
end
56+
end
57+
end
58+
end
59+
4860
JQ = Element

ruby/hyper-component/spec/client_features/dsl_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,20 @@ class Foo
244244
expect(page.body[-80..-19]).to include('<span data-size="12">Hyperstack::Component::Element</span>')
245245
end
246246

247+
it "has a dom_node method" do
248+
mount 'Foo' do
249+
class Foo
250+
include Hyperstack::Component
251+
include Hyperstack::State::Observable
252+
after_mount { mutate @my_node_id = JQ[dom_node].id }
253+
render do
254+
SPAN(id: 'foo') { "my id is '#{@my_node_id}'" }
255+
end
256+
end
257+
end
258+
expect(page).to have_content("my id is 'foo'")
259+
end
260+
247261
it "can use the dangerously_set_inner_HTML param" do
248262
mount 'Foo' do
249263
class Foo

ruby/hyper-component/spec/client_features/refs_callback_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,18 @@ class Foo
7777
end
7878
expect(page).to have_content('I am [object HTMLDivElement]')
7979
end
80+
81+
it 'can get the a jquery wrapped reference using the set_jq method' do
82+
mount 'Foo' do
83+
class Foo
84+
render do
85+
DIV(ref: set_jq(:the_ref)) { @the_ref.inspect }
86+
end
87+
after_mount do
88+
force_update!
89+
end
90+
end
91+
end
92+
expect(page).to have_content('#<Element [<div>]>')
93+
end
8094
end

0 commit comments

Comments
 (0)