Skip to content

Commit e11d73a

Browse files
authored
Test <Focus /> component (#96)
1 parent ef122e0 commit e11d73a

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/components/Focus.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
import * as React from 'react'
22
import TestRenderer from 'react-test-renderer'
33
import { Focus } from '../../src'
4+
import { last } from './utils'
45

56
test('<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
})

0 commit comments

Comments
 (0)