Skip to content

Commit 09d7b43

Browse files
committed
feat(dropdown): test handleGlobalClick
1 parent 5daf50c commit 09d7b43

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/dropdown/tests/unit/Dropdown.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ import { shallowMount, createLocalVue } from '@vue/test-utils'
22

33
import Dropdown from '@p/dropdown/src/index.vue'
44

5+
document.body.innerHTML = `
6+
<div>
7+
<button id="btn1">btn 1 </button>
8+
<button id="btn2">btn 2 </button>
9+
<button id="btn3">btn 3 </button>
10+
<a href="#" id="test-link">test</a>
11+
</div>
12+
`
13+
514
const localVue = createLocalVue()
615

716
describe('Dropdown', () => {
@@ -96,6 +105,18 @@ describe('Dropdown', () => {
96105

97106
expect(lastItem.element).toBe(document.activeElement)
98107
})
108+
109+
it('closes the menu if click happens outside of it', async () => {
110+
button.trigger('keydown.down')
111+
112+
await wrapper.vm.$nextTick()
113+
114+
document.getElementById('test-link').click()
115+
116+
await wrapper.vm.$nextTick()
117+
118+
expect(wrapper.vm.$refs.menu).toBeUndefined()
119+
})
99120
})
100121

101122
describe('Menu toggle button', () => {

0 commit comments

Comments
 (0)