Sha256: 7a229db1449a27ca9c4192c6ae8e6c44ae48d04b5f63ddb005dbf599f0adffb3

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

module React
  module Test
    class Session
      DSL_METHODS = %i[mount instance native element update_params
        force_update! html].freeze

      def mount(component_klass, params = {})
        @element = React.create_element(component_klass, params)
        instance
      end

      def instance
        unless @instance
          @native = Native(`React.addons.TestUtils.renderIntoDocument(#{element.to_n})`)
          @instance = `#{@native.to_n}._getOpalInstance()`
        end
        @instance
      end

      def native
        @native
      end

      def element
        @element
      end

      def update_params(params)
        cloned_element = React::Element.new(`React.cloneElement(#{self.element.to_n}, #{params.to_n})`)
        prev_container = `#{self.instance.dom_node}.parentNode`
        React.render(cloned_element, prev_container)
        nil
      end

      def force_update!
        native.force_update!
      end

      def html
        # How can we get the current ReactElement w/o violating private APIs?
        elem = Native(native[:_reactInternalInstance][:_currentElement])
        React.render_to_static_markup(elem)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
hyper-react-0.10.0 lib/react/test/session.rb
reactrb-0.9.0 lib/react/test/session.rb