Skip to content

Commit

Permalink
test(fireEvent): Add expected behavior for blur/focus in React (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Aug 4, 2020
1 parent b82773c commit 0405f56
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/__tests__/events.js
Expand Up @@ -211,3 +211,30 @@ test('calling `fireEvent` directly works too', () => {
}),
)
})

test('blur/foucs bubbles in react', () => {
const handleBlur = jest.fn()
const handleBubbledBlur = jest.fn()
const handleFocus = jest.fn()
const handleBubbledFocus = jest.fn()
const {container} = render(
<div onBlur={handleBubbledBlur} onFocus={handleBubbledFocus}>
<button onBlur={handleBlur} onFocus={handleFocus} />
</div>,
)
const button = container.firstChild.firstChild

fireEvent.focus(button)

expect(handleBlur).toHaveBeenCalledTimes(0)
expect(handleBubbledBlur).toHaveBeenCalledTimes(0)
expect(handleFocus).toHaveBeenCalledTimes(1)
expect(handleBubbledFocus).toHaveBeenCalledTimes(1)

fireEvent.blur(button)

expect(handleBlur).toHaveBeenCalledTimes(1)
expect(handleBubbledBlur).toHaveBeenCalledTimes(1)
expect(handleFocus).toHaveBeenCalledTimes(1)
expect(handleBubbledFocus).toHaveBeenCalledTimes(1)
})

0 comments on commit 0405f56

Please sign in to comment.