This repository has been archived by the owner on Oct 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from Donnadieu/edge
Added to_key methods and tests
- Loading branch information
Showing
4 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'spec_helper' | ||
|
||
describe 'key_to_react helper', js: true do | ||
it "will use the use the to_key method to get the react key" do | ||
mount "TestComponent" do | ||
class MyTestClass | ||
attr_reader :to_key_called | ||
def to_key | ||
@to_key_called = true | ||
super | ||
end | ||
end | ||
class TestComponent < Hyperloop::Component | ||
before_mount { @test_object = MyTestClass.new } | ||
render do | ||
DIV(key: @test_object) { TestComponent2(test_object: @test_object) } | ||
end | ||
end | ||
class TestComponent2 < Hyperloop::Component | ||
param :test_object | ||
render do | ||
"to key was called!" if params.test_object.to_key_called | ||
end | ||
end | ||
end | ||
pause | ||
expect(page).to have_content('to key was called!') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'spec_helper' | ||
|
||
describe 'to_key helper', js: true do | ||
it "has added 'to_key' method to Object and each key is different" do | ||
expect_evaluate_ruby do | ||
Object.new.to_key != Object.new.to_key | ||
end.to be_truthy | ||
end | ||
|
||
it "to_key return 'self' for String objects" do | ||
expect_evaluate_ruby do | ||
debugger | ||
"hello".to_key == "hello" | ||
end.to be_truthy | ||
end | ||
|
||
it "to_key return 'self' for Number objects" do | ||
expect_evaluate_ruby do | ||
12.to_key == 12 | ||
end.to be_truthy | ||
end | ||
|
||
it "to_key return 'self' for Boolean objects" do | ||
expect_evaluate_ruby do | ||
true.to_key == true && false.to_key == false | ||
end.to be_truthy | ||
end | ||
end |