Sha256: 6a12c3bd01f6f8106cac256093ba393895999fdf9f3582e3a08497d3eaf05886

Contents?: true

Size: 1.01 KB

Versions: 24

Compression:

Stored size: 1.01 KB

Contents

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

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

      def instance
        unless @instance
          @container = `document.createElement('div')`
          @instance = React.render(@element, @container)
        end
        @instance
      end

      def update_params(params, &block)
        cloned_element = React::Element.new(`React.cloneElement(#{@element.to_n}, #{params.to_n})`)
        React.render(cloned_element, @container, &block)
        nil
      end

      def html
        html = `#@container.innerHTML`
        %x{
            var REGEX_REMOVE_ROOT_IDS = /\s?data-reactroot="[^"]*"/g;
            var REGEX_REMOVE_IDS = /\s?data-reactid="[^"]+"/g;
            html = html.replace(REGEX_REMOVE_ROOT_IDS, '');
            html = html.replace(REGEX_REMOVE_IDS, '');
        }
        return html
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
hyper-component-0.99.6 lib/react/test/session.rb
hyper-component-0.99.5 lib/react/test/session.rb
hyper-component-0.99.4 lib/react/test/session.rb
hyper-component-0.99.3 lib/react/test/session.rb
hyper-component-0.99.2 lib/react/test/session.rb
hyper-component-0.99.1 lib/react/test/session.rb
hyper-component-0.99.0 lib/react/test/session.rb
hyper-react-1.0.0.lap28 lib/react/test/session.rb
hyper-react-1.0.0.lap27 lib/react/test/session.rb
hyper-react-1.0.0.lap26 lib/react/test/session.rb
hyper-react-1.0.0.lap25 lib/react/test/session.rb
hyper-react-1.0.0.lap24 lib/react/test/session.rb
hyper-react-1.0.0.lap23 lib/react/test/session.rb
hyper-react-1.0.0.lap22 lib/react/test/session.rb
hyper-react-1.0.0.lap21 lib/react/test/session.rb
hyper-react-0.12.7 lib/react/test/session.rb
hyper-react-0.12.6 lib/react/test/session.rb
hyper-react-0.12.5 lib/react/test/session.rb
hyper-react-0.12.4 lib/react/test/session.rb
hyper-react-0.12.3 lib/react/test/session.rb