@@ -3,54 +3,37 @@ import React from 'react'
33import findAll from './find-all'
44
55export default ( component ) => {
6- let items , selectedIndex
7-
6+ let items
7+
88 const shallowRenderer = TestUtils . createRenderer ( )
99 shallowRenderer . render ( component )
1010 const instance = shallowRenderer . getRenderOutput ( ) ;
1111
1212 const find = ( term , child ) => {
1313 const selector = term . charAt ( 0 )
14+
1415 switch ( selector ) {
1516 case '.' :
1617 items = findAll ( instance , child => child . props ? child . props . className == term . slice ( 1 ) : false )
17- return proxy
18+ return { ... items [ 0 ] . props , ... utils }
1819 case '#' :
1920 items = findAll ( instance , child => child . props ? child . props . id == term . slice ( 1 ) : false )
20- return proxy
21+ return { ... items [ 0 ] . props , ... utils }
2122 default :
22- return proxy
23+ return utils
2324 }
2425 }
2526
26- const first = ( ) => {
27- selectedIndex = 0
28- return proxy
29- }
30-
31- const last = ( ) => {
32- selectedIndex = items . length - 1
33- return proxy
34- }
35-
36- const get = ( index ) => {
37- selectedIndex = index
38- return proxy
39- }
27+ const first = ( ) => items [ 0 ] . props
28+ const last = ( ) => items [ items . length - 1 ] . props
29+ const get = ( index ) => items [ index ] . props
4030
4131 const utils = {
42- props : instance . props ,
4332 find,
4433 first,
4534 last,
46- get
35+ get,
4736 }
4837
49- const proxy = Proxy . create ( {
50- get : ( proxy , name ) => {
51- if ( utils [ name ] ) return value => utils [ name ] ( value )
52- return items [ selectedIndex || 0 ] . props [ name ]
53- }
54- } )
55- return proxy
38+ return utils
5639}
0 commit comments