test(auto-complete): update test (#1365)

Co-authored-by: unknown <liyang@xiaoyouzi.com>
This commit is contained in:
小魔王 2021-10-16 16:11:30 +08:00 committed by GitHub
parent a2e5f557cb
commit 15c97c5ca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,4 +70,33 @@ describe('n-auto-complete', () => {
wrapper.unmount()
})
})
it('should work with `getShow` prop', async () => {
const options: AutoCompleteProps['options'] = [
'@gmail.com',
'@163.com',
'@qq.com'
].map((suffix) => {
const prefix = 'test'
return {
label: prefix + suffix,
value: prefix + suffix
}
})
const wrapper = mount(NAutoComplete)
await wrapper.setProps({
getShow: (value: string | null) => {
if (value === 'a') {
return true
}
return false
},
options: options
})
expect(document.querySelector('.n-auto-complete-menu')).toEqual(null)
wrapper.find('input').setValue('a')
await wrapper.find('input').trigger('focus')
expect(document.querySelector('.n-auto-complete-menu')).not.toEqual(null)
wrapper.unmount()
})
})