Sha256: 3272f01f0d920e8bd353e99f4ac6ae1bbad9375dbec25209aa046b91f7cd252e

Contents?: true

Size: 1.33 KB

Versions: 23

Compression:

Stored size: 1.33 KB

Contents

module React
  module Test
    module Matchers
      class RenderHTMLMatcher
        def initialize(expected)
          @expected = expected
          @params = {}
        end

        def with_params(params)
          @params = params
          self
        end

        def matches?(component)
          @component = component
          @actual = render_to_html
          @expected == @actual
        end

        def failure_message
          failure_string
        end

        def failure_message_when_negated
          failure_string(:negative)
        end

        alias negative_failure_message failure_message_when_negated

        private

        def render_to_html
          element = React.create_element(@component, @params)
          React::Server.render_to_static_markup(element)
        end

        def failure_string(negative = false)
          str = "expected '#{@component.name}' with params '#{@params}' to "
          str = str + "not " if negative
          str = str + "render '#{@expected}', but '#{@actual}' was rendered."
          str
        end
      end

      def render_static_html(*args)
        RenderHTMLMatcher.new(*args)
      end

      def render(*args)
        %x{ console.error("Warning: `render` matcher is deprecated in favor of `render_static_html`."); }
        RenderHTMLMatcher.new(*args)
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

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