Sha256: 5b85a89645b238c41b4e5eb3f3e3d8f755cce3c051d4ef2d7419ab05798091c7

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

require 'spec_helper'

describe 'An Example from the react.rb doc', js: true do
  it 'produces the correct result' do
    mount 'HelloMessage' do
      class HelloMessage
        include React::Component
        def render
          div { "Hello World!" }
        end
      end
    end
    expect(page).to have_xpath('//div', text: 'Hello World!')
  end
end

describe 'Adding state to a component (second tutorial example)', js: true do
  before :each do
    on_client do
      class HelloMessage2
        include React::Component
        define_state(:user_name) { '@catmando' }
        def render
          div { "Hello #{state.user_name}" }
        end
      end
    end
  end

  it "produces the correct result" do
    mount 'HelloMessage2'
    expect(page).to have_xpath('//div', text: 'Hello @catmando')
  end

  it 'renders to the document' do
    evaluate_ruby do
      ele = JS.call(:eval, "document.body.appendChild(document.createElement('div'))")
      React.render(React.create_element(HelloMessage2), ele)
    end
    expect(page).to have_xpath('//div', text: 'Hello @catmando')
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hyper-react-1.0.0.lap28 spec/react/tutorial/tutorial_spec.rb
hyper-react-1.0.0.lap27 spec/react/tutorial/tutorial_spec.rb
hyper-react-1.0.0.lap26 spec/react/tutorial/tutorial_spec.rb
hyper-react-1.0.0.lap25 spec/react/tutorial/tutorial_spec.rb
hyper-react-1.0.0.lap24 spec/react/tutorial/tutorial_spec.rb
hyper-react-1.0.0.lap23 spec/react/tutorial/tutorial_spec.rb
hyper-react-1.0.0.lap22 spec/react/tutorial/tutorial_spec.rb
hyper-react-1.0.0.lap21 spec/react/tutorial/tutorial_spec.rb