Sha256: 8cd9d6839259bef09e22a98b5bc12b9e2c489c1ffc36bfa0f5bd1986328cea09

Contents?: true

Size: 1.79 KB

Versions: 9

Compression:

Stored size: 1.79 KB

Contents

require 'spec_helper'

if opal?
describe 'opal-jquery extensions' do
  describe 'Element' do
    after(:each) do
      React::API.clear_component_class_cache
    end

    it 'will reuse the wrapper componet class for the same Element' do
      stub_const 'Foo', Class.new(React::Component::Base)
      Foo.class_eval do
        param :name
        def render
          "hello #{params.name}"
        end

        def component_will_unmount

        end
      end

      expect_any_instance_of(Foo).to_not receive(:component_will_unmount)

      test_div = Element.new(:div)
      test_div.render { Foo(name: 'fred') }
      test_div.render { Foo(name: 'freddy') }
      expect(Element[test_div].find('span').html).to eq('hello freddy')
    end

    it 'renders a top level component using render with a block' do
      stub_const 'Foo', Class.new(React::Component::Base)
      Foo.class_eval do
        param :name
        def render
          "hello #{params.name}"
        end
      end
      test_div = Element.new(:div)
      test_div.render { Foo(name: 'fred') }
      expect(Element[test_div].find('span').html).to eq('hello fred')
    end

    it 'renders a top level component using render with a container and params ' do
      test_div = Element.new(:div)
      test_div.render(:span, id: :render_test_span) { 'hello' }
      expect(Element[test_div].find('#render_test_span').html).to eq('hello')
    end

    it 'will find the DOM node given a react element' do
      stub_const 'Foo', Class.new(React::Component::Base)
      Foo.class_eval do
        def render
          div { 'hello' }
        end
      end

      expect(Element[renderToDocument(Foo)].html).to eq('hello')
    end

    it "accepts plain js object as selector" do
      expect {
        Element[`window`]
      }.not_to raise_error
    end
  end
end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hyper-react-0.12.7 spec/react/opal_jquery_extensions_spec.rb
hyper-react-0.12.6 spec/react/opal_jquery_extensions_spec.rb
hyper-react-0.12.5 spec/react/opal_jquery_extensions_spec.rb
hyper-react-0.12.4 spec/react/opal_jquery_extensions_spec.rb
hyper-react-0.12.3 spec/react/opal_jquery_extensions_spec.rb
hyper-react-0.12.2 spec/react/opal_jquery_extensions_spec.rb
hyper-react-0.12.1 spec/react/opal_jquery_extensions_spec.rb
hyper-react-0.12.0 spec/react/opal_jquery_extensions_spec.rb
hyper-react-0.11.0 spec/react/opal_jquery_extensions_spec.rb