File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 11import * as React from 'react'
22import TestRenderer from 'react-test-renderer'
33import { Focus } from '../../src'
4+ import { last } from './utils'
45
56test ( '<Focus />' , ( ) => {
67 const renderFn = jest . fn ( ) . mockReturnValue ( null )
78 TestRenderer . create ( < Focus render = { renderFn } /> )
8- // TODO
9+ const lastCalled = ( ) => last ( renderFn . mock . calls ) [ 0 ]
10+
11+ expect ( renderFn ) . toHaveBeenCalledTimes ( 1 )
12+ expect ( lastCalled ( ) . isFocused ) . toEqual ( false )
13+
14+ lastCalled ( ) . bind . onFocus ( )
15+ expect ( renderFn ) . toHaveBeenCalledTimes ( 2 )
16+ expect ( lastCalled ( ) . isFocused ) . toEqual ( true )
17+
18+ lastCalled ( ) . bind . onBlur ( )
19+ expect ( lastCalled ( ) . isFocused ) . toEqual ( false )
20+ } )
21+
22+ test ( '<Focus onChange />' , ( ) => {
23+ const renderFn = jest . fn ( ) . mockReturnValue ( null )
24+ const onChangeFn = jest . fn ( )
25+ const lastCalled = ( ) => last ( renderFn . mock . calls ) [ 0 ]
26+ TestRenderer . create ( < Focus onChange = { onChangeFn } render = { renderFn } /> )
27+
28+ expect ( onChangeFn ) . toHaveBeenCalledTimes ( 0 )
29+
30+ lastCalled ( ) . bind . onFocus ( )
31+ expect ( onChangeFn ) . toHaveBeenCalledTimes ( 1 )
32+ expect ( onChangeFn ) . lastCalledWith ( { isFocused : true } )
933} )
You can’t perform that action at this time.
0 commit comments