/
blur.js
66 lines (59 loc) 路 1.65 KB
/
blur.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import {blur} from '../blur'
import {focus} from '../focus'
import {setup} from './helpers/utils'
test('blur a button', () => {
const {element, getEventSnapshot, clearEventCalls} = setup(`<button />`)
focus(element)
clearEventCalls()
blur(element)
expect(getEventSnapshot()).toMatchInlineSnapshot(`
Events fired on: button
button - blur
button - focusout
`)
expect(element).not.toHaveFocus()
})
test('no events fired on an unblurable input', () => {
const {element, getEventSnapshot, clearEventCalls} = setup(`<div />`)
focus(element)
clearEventCalls()
blur(element)
expect(getEventSnapshot()).toMatchInlineSnapshot(
`No events were fired on: div`,
)
expect(element).not.toHaveFocus()
})
test('blur with tabindex', () => {
const {element, getEventSnapshot, clearEventCalls} = setup(
`<div tabindex="0" />`,
)
focus(element)
clearEventCalls()
blur(element)
expect(getEventSnapshot()).toMatchInlineSnapshot(`
Events fired on: div
div - blur
div - focusout
`)
expect(element).not.toHaveFocus()
})
test('no events fired on a disabled blurable input', () => {
const {element, getEventSnapshot, clearEventCalls} = setup(
`<button disabled />`,
)
focus(element)
clearEventCalls()
blur(element)
expect(getEventSnapshot()).toMatchInlineSnapshot(
`No events were fired on: button`,
)
expect(element).not.toHaveFocus()
})
test('no events fired if the element is not focused', () => {
const {element, getEventSnapshot} = setup(`<button />`)
blur(element)
expect(getEventSnapshot()).toMatchInlineSnapshot(
`No events were fired on: button`,
)
expect(element).not.toHaveFocus()
})