spec/react/dsl_spec.rb in hyper-react-0.10.0 vs spec/react/dsl_spec.rb in hyper-react-0.11.0

- old
+ new

@@ -1,9 +1,9 @@ require 'spec_helper' if opal? -describe 'the React DSL' do +describe 'the React DSL', type: :component do context "render macro" do it "can define the render method with the render macro with a html tag container" do stub_const 'Foo', Class.new @@ -12,11 +12,11 @@ render(:div, class: :foo) do "hello" end end - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div class="foo">hello</div>') + expect(Foo).to render_static_html('<div class="foo">hello</div>') end it "can define the render method with the render macro without a container" do stub_const 'Foo', Class.new Foo.class_eval do @@ -24,11 +24,11 @@ render do "hello" end end - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span>hello</span>') + expect(Foo).to render_static_html('<span>hello</span>') end it "can define the render method with the render macro with a application defined container" do stub_const 'Bar', Class.new(React::Component::Base) Bar.class_eval do @@ -38,11 +38,11 @@ stub_const 'Foo', Class.new(React::Component::Base) Foo.class_eval do render Bar, p1: "fred" end - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span>hello fred</span>') + expect(Foo).to render_static_html('<span>hello fred</span>') end end it "will turn the last string in a block into a element" do stub_const 'Foo', Class.new @@ -51,11 +51,11 @@ def render div { "hello" } end end - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>hello</div>') + expect(Foo).to render_static_html('<div>hello</div>') end it "will pass converted props through event handlers" do stub_const 'Foo', Class.new Foo.class_eval do @@ -75,11 +75,11 @@ def render DIV { "hello" } end end - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>hello</div>') + expect(Foo).to render_static_html('<div>hello</div>') end it "has a .span short hand String method" do stub_const 'Foo', Class.new Foo.class_eval do @@ -87,11 +87,11 @@ def render div { "hello".span; "goodby".span } end end - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div><span>hello</span><span>goodby</span></div>') + expect(Foo).to render_static_html('<div><span>hello</span><span>goodby</span></div>') end it "has a .br short hand String method" do stub_const 'Foo', Class.new Foo.class_eval do @@ -111,11 +111,11 @@ def render table { tr { "hello".td } } end end - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<table><tr><td>hello</td></tr></table>') + expect(Foo).to render_static_html('<table><tr><td>hello</td></tr></table>') end it "has a .para short hand String method" do stub_const 'Foo', Class.new Foo.class_eval do @@ -123,11 +123,11 @@ def render div { "hello".para } end end - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div><p>hello</p></div>') + expect(Foo).to render_static_html('<div><p>hello</p></div>') end it 'can do a method call on a class name that is not a direct sibling' do stub_const 'Mod', Module.new stub_const 'Mod::NestedMod', Module.new @@ -139,12 +139,12 @@ Mod::NestedMod::NestedComp.class_eval do render do Comp() end end - expect(React.render_to_static_markup(React.create_element(Mod::NestedMod::NestedComp))) - .to eq('<span>Mod::Comp</span>') + expect(Mod::NestedMod::NestedComp) + .to render_static_html('<span>Mod::Comp</span>') end it 'raises a meaningful error if a Constant Name is not actually a component' do stub_const 'Mod', Module.new stub_const 'Mod::NestedMod', Module.new @@ -185,11 +185,11 @@ def render Mod::Bar() end end - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span>a man walks into a bar</span>') + expect(Foo).to render_static_html('<span>a man walks into a bar</span>') end it "can add class names by the haml .class notation" do stub_const 'Mod::Bar', Class.new Mod::Bar.class_eval do @@ -204,11 +204,11 @@ def render Mod::Bar().the_class.other_class end end - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span class="other-class the-class">a man walks into a bar</span>') + expect(Foo).to render_static_html('<span class="other-class the-class">a man walks into a bar</span>') end it "can use the 'class' keyword for classes" do stub_const 'Foo', Class.new Foo.class_eval do @@ -216,11 +216,11 @@ def render span(class: "the-class") { "hello" } end end - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span class="the-class">hello</span>') + expect(Foo).to render_static_html('<span class="the-class">hello</span>') end it "can generate a unrendered node using the .as_node method" do # div { "hello" }.as_node stub_const 'Foo', Class.new #(React::Component::Base) Foo.class_eval do @@ -228,11 +228,12 @@ def render span(data: {size: 12}) { "hello".span.as_node.class.name }.as_node.render end end - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span data-size="12">React::Element</span>') + expect(Foo) + .to render_static_html('<span data-size="12">React::Element</span>') end it "can use the dangerously_set_inner_HTML param" do stub_const 'Foo', Class.new Foo.class_eval do @@ -240,11 +241,11 @@ def render div(dangerously_set_inner_HTML: { __html: "Hello&nbsp;&nbsp;Goodby" }) end end - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>Hello&nbsp;&nbsp;Goodby</div>') + expect(Foo).to render_static_html('<div>Hello&nbsp;&nbsp;Goodby</div>') end it 'should convert a hash param to hyphenated html attributes if in React::HASH_ATTRIBUTES' do stub_const 'Foo', Class.new Foo.class_eval do @@ -252,12 +253,12 @@ def render div(data: { foo: :bar }, aria: { foo_bar: :foo }) end end - expect(React.render_to_static_markup(React.create_element(Foo))) - .to eq('<div data-foo="bar" aria-foo-bar="foo"></div>') + expect(Foo) + .to render_static_html('<div data-foo="bar" aria-foo-bar="foo"></div>') end it 'should not convert a hash param to hyphenated html attributes if not in React::HASH_ATTRIBUTES' do stub_const 'Foo', Class.new Foo.class_eval do @@ -265,12 +266,14 @@ def render div(title: { bar: :foo }) end end - expect(React.render_to_static_markup(React.create_element(Foo))) - .to eq('<div title="{&quot;bar&quot;=&gt;&quot;foo&quot;}"></div>') + expect(Foo) + .to render_static_html( + '<div title="{&quot;bar&quot;=&gt;&quot;foo&quot;}"></div>' + ) end it "will remove all elements passed as params from the rendering buffer" do stub_const 'X2', Class.new X2.class_eval do @@ -288,9 +291,9 @@ def render X2(ele: b { "hello" }) end end - expect(React.render_to_static_markup(React.create_element(Test))).to eq('<div><b>hello</b><b>hello</b></div>') + expect(Test).to render_static_html('<div><b>hello</b><b>hello</b></div>') end end end