test(cascader): test (#1251)

* test(cascader): Update cascader component test

* test(cascader): Update cascader component test

* test(cascader): Update cascader component test
This commit is contained in:
songjianet 2021-09-28 23:28:39 +08:00 committed by GitHub
parent d2401fc7ad
commit 6fc02b6384
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -159,4 +159,42 @@ describe('n-cascader', () => {
expect(onFocus).toHaveBeenCalled()
wrapper.unmount()
})
it('should be active after clicked', async () => {
const wrapper = mount(NCascader, {
attachTo: document.body,
props: {
options: getOptions()
}
})
await wrapper.find('.n-base-selection').trigger('click')
expect(wrapper.find('.n-base-selection--active').exists()).toBe(true)
expect(document.querySelector('.n-cascader-menu')).not.toEqual(null)
await wrapper.find('.n-base-selection').trigger('click')
expect(wrapper.find('.n-base-selection--active').exists()).toBe(false)
expect(document.querySelector('.n-cascader-menu')).toEqual(null)
wrapper.unmount()
})
it('should be active after click outside', async () => {
const mousedownEvent = new MouseEvent('mousedown', { bubbles: true })
const mouseupEvent = new MouseEvent('mouseup', { bubbles: true })
const wrapper = mount(NCascader, {
attachTo: document.body,
props: {
options: getOptions()
}
})
await wrapper.find('.n-base-selection').trigger('click')
expect(document.querySelector('.n-cascader-menu')).not.toEqual(null)
await document.body.click()
await document.body.dispatchEvent(mousedownEvent)
await document.body.dispatchEvent(mouseupEvent)
expect(document.querySelector('.n-cascader-menu')).toEqual(null)
wrapper.unmount()
})
})