Skip to content

Commit

Permalink
adds specs and closes #62
Browse files Browse the repository at this point in the history
  • Loading branch information
catmando committed Jan 16, 2019
1 parent 719642a commit 96b01e9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ruby/hyper-component/lib/hyperstack/ext/component/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,16 @@ def self.[](selector)
Element.expose :mount_components
end

module Hyperstack
module Internal
module Component
module InstanceMethods
def set_jq(var)
->(val) { set(var).call(JQ[val]) }
end
end
end
end
end

JQ = Element
14 changes: 14 additions & 0 deletions ruby/hyper-component/spec/client_features/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ class Foo
expect(page.body[-80..-19]).to include('<span data-size="12">Hyperstack::Component::Element</span>')
end

it "has a dom_node method" do
mount 'Foo' do
class Foo
include Hyperstack::Component
include Hyperstack::State::Observable
after_mount { mutate @my_node_id = JQ[dom_node].id }
render do
SPAN(id: 'foo') { "my id is '#{@my_node_id}'" }
end
end
end
expect(page).to have_content("my id is 'foo'")
end

it "can use the dangerously_set_inner_HTML param" do
mount 'Foo' do
class Foo
Expand Down
14 changes: 14 additions & 0 deletions ruby/hyper-component/spec/client_features/refs_callback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,18 @@ class Foo
end
expect(page).to have_content('I am [object HTMLDivElement]')
end

it 'can get the a jquery wrapped reference using the set_jq method' do
mount 'Foo' do
class Foo
render do
DIV(ref: set_jq(:the_ref)) { @the_ref.inspect }
end
after_mount do
force_update!
end
end
end
expect(page).to have_content('#<Element [<div>]>')
end
end

0 comments on commit 96b01e9

Please sign in to comment.