@@ -51,6 +51,38 @@ class TodoList extends Component {
5151 }
5252}
5353
54+ class SVGList extends Component {
55+ state = {
56+ items : [ 'hello' , 'world' , 'click' , 'me' ]
57+ } ;
58+
59+ handleAdd ( item ) {
60+ let { items } = this . state ;
61+ items = items . concat ( item ) ;
62+ this . setState ( { items } ) ;
63+ }
64+
65+ handleRemove ( i ) {
66+ let { items } = this . state ;
67+ items . splice ( i , 1 ) ;
68+ this . setState ( { items } ) ;
69+ }
70+
71+ render ( _ , { items } ) {
72+ return (
73+ < svg >
74+ < CSSTransitionGroup transitionName = "example" component = "g" >
75+ { items . map ( ( item , i ) => (
76+ < text key = { item } className = "item" >
77+ { item }
78+ </ text >
79+ ) ) }
80+ </ CSSTransitionGroup >
81+ </ svg >
82+ ) ;
83+ }
84+ }
85+
5486
5587const Nothing = ( ) => null ;
5688
@@ -99,17 +131,74 @@ describe('CSSTransitionGroup', () => {
99131 list . handleAdd ( Date . now ( ) ) ;
100132
101133 setTimeout ( ( ) => {
102- expect ( $ ( '.item' ) ) . to . have . length ( 4 ) ;
134+ expect ( $ ( '.item' ) ) . to . have . length ( 5 ) ;
103135
104- expect ( $ ( '.item' ) [ 3 ] . className ) . to . contain ( 'example-enter' ) ;
105- expect ( $ ( '.item' ) [ 3 ] . className ) . to . contain ( 'example-enter-active' ) ;
136+ expect ( $ ( '.item' ) [ 4 ] . className ) . to . contain ( 'example-enter' ) ;
137+ expect ( $ ( '.item' ) [ 4 ] . className ) . to . contain ( 'example-enter-active' ) ;
106138 } , 500 ) ;
107139
140+ setTimeout ( ( ) => {
141+ expect ( $ ( '.item' ) ) . to . have . length ( 5 ) ;
142+
143+ expect ( $ ( '.item' ) [ 4 ] . className ) . not . to . contain ( 'example-enter' ) ;
144+ expect ( $ ( '.item' ) [ 4 ] . className ) . not . to . contain ( 'example-enter-active' ) ;
145+
146+ done ( ) ;
147+ } , 1400 ) ;
148+ } ) ;
149+ } ) ;
150+
151+ describe ( 'CSSTransitionGroup: SVG' , ( ) => {
152+ let container = document . createElement ( 'div' ) ,
153+ list , root ;
154+ document . body . appendChild ( container ) ;
155+
156+ let $ = s => [ ] . slice . call ( container . querySelectorAll ( s ) ) ;
157+
158+ beforeEach ( ( ) => {
159+ root = render ( < div > < Nothing /> </ div > , container , root ) ;
160+ root = render ( < div > < SVGList ref = { c => list = c } /> </ div > , container , root ) ;
161+ } ) ;
162+
163+ afterEach ( ( ) => {
164+ list = null ;
165+ } ) ;
166+
167+ it ( 'create works' , ( ) => {
168+ expect ( $ ( '.item' ) ) . to . have . length ( 4 ) ;
169+ } ) ;
170+
171+ it ( 'transitionLeave works' , done => {
172+ list . handleRemove ( 0 ) ;
173+
108174 setTimeout ( ( ) => {
109175 expect ( $ ( '.item' ) ) . to . have . length ( 4 ) ;
110176
111- expect ( $ ( '.item' ) [ 3 ] . className ) . not . to . contain ( 'example-enter' ) ;
112- expect ( $ ( '.item' ) [ 3 ] . className ) . not . to . contain ( 'example-enter-active' ) ;
177+ expect ( $ ( '.item' ) [ 0 ] . classList . contains ( 'example-leave' ) ) ;
178+ expect ( $ ( '.item' ) [ 0 ] . classList . contains ( 'example-leave-active' ) ) ;
179+ } , 100 ) ;
180+
181+ setTimeout ( ( ) => {
182+ expect ( $ ( '.item' ) ) . to . have . length ( 3 ) ;
183+ done ( ) ;
184+ } , 1400 ) ;
185+ } ) ;
186+
187+ it ( 'transitionEnter works' , done => {
188+ list . handleAdd ( Date . now ( ) ) ;
189+
190+ setTimeout ( ( ) => {
191+ expect ( $ ( '.item' ) ) . to . have . length ( 5 ) ;
192+
193+ expect ( $ ( '.item' ) [ 4 ] . classList . contains ( 'example-enter' ) ) ;
194+ expect ( $ ( '.item' ) [ 4 ] . classList . contains ( 'example-enter-active' ) ) ;
195+ } , 500 ) ;
196+
197+ setTimeout ( ( ) => {
198+ expect ( $ ( '.item' ) ) . to . have . length ( 5 ) ;
199+
200+ expect ( ! $ ( '.item' ) [ 4 ] . classList . contains ( 'example-enter' ) ) ;
201+ expect ( ! $ ( '.item' ) [ 4 ] . classList . contains ( 'example-enter-active' ) ) ;
113202
114203 done ( ) ;
115204 } , 1400 ) ;
0 commit comments