This repository was archived by the owner on Oct 19, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +76
-0
lines changed
Expand file tree Collapse file tree 3 files changed +76
-0
lines changed Original file line number Diff line number Diff line change 1+ require 'react/test/session'
2+ require 'react/test/dsl'
3+
4+ module React
5+ module Test
6+ class << self
7+ def current_session
8+ @current_session ||= Session . new
9+ end
10+
11+ def reset_session!
12+ @current_session = nil
13+ end
14+ end
15+ end
16+ end
Original file line number Diff line number Diff line change 1+ require 'react/test'
2+
3+ module React
4+ module Test
5+ module DSL
6+ def component
7+ React ::Test . current_session
8+ end
9+
10+ Session ::DSL_METHODS . each do |method |
11+ define_method method do |*args , &block |
12+ component . public_send ( method , *args , &block )
13+ end
14+ end
15+ end
16+ end
17+ end
Original file line number Diff line number Diff line change 1+ require 'spec_helper'
2+
3+ if opal?
4+ RSpec . describe React ::Test ::DSL do
5+ describe 'the DSL' do
6+ let ( :session ) { Class . new { include React ::Test ::DSL } . new }
7+
8+ before do
9+ React ::Test . reset_session!
10+
11+ stub_const 'Greeter' , Class . new
12+ Greeter . class_eval do
13+ include React ::Component
14+
15+ params do
16+ optional :message
17+ optional :from
18+ end
19+
20+ def render
21+ span { "Hello #{ params . message } " }
22+ end
23+ end
24+ end
25+
26+ it 'is possible to include it in another class' do
27+ session . mount ( Greeter )
28+ expect ( session . instance ) . to be_a ( Greeter )
29+ end
30+
31+ it "should provide a 'component' shortcut for more expressive tests" do
32+ session . component . mount ( Greeter )
33+ expect ( session . component . instance ) . to be_a ( Greeter )
34+ end
35+
36+ React ::Test ::Session ::DSL_METHODS . each do |method |
37+ it "responds to all DSL method: #{ method } " do
38+ expect ( session ) . to respond_to ( method )
39+ end
40+ end
41+ end
42+ end
43+ end
You can’t perform that action at this time.
0 commit comments