Sha256: e55effc6ceb2828703a9bc3c6e6cf02ea8e6b237a82f7f54d0ac8e6b61df24dd

Contents?: true

Size: 1.37 KB

Versions: 5

Compression:

Stored size: 1.37 KB

Contents

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
  
  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
    expect(page).to have_content('to key was called!')
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hyper-react-1.0.0.lap28 spec/react/to_key_spec.rb
hyper-react-1.0.0.lap27 spec/react/to_key_spec.rb
hyper-react-1.0.0.lap26 spec/react/to_key_spec.rb
hyper-react-1.0.0.lap25 spec/react/to_key_spec.rb
hyper-react-1.0.0.lap24 spec/react/to_key_spec.rb