fix(message-box): - fix message box unit test error (#433)

This commit is contained in:
jeremywu 2020-10-19 15:05:37 +08:00 committed by GitHub
parent 2d13a7091b
commit f4f81af246
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 10 deletions

View File

@ -1,5 +1,6 @@
import MessageBox from '../src/messageBox'
import { sleep } from '@element-plus/test-utils'
import { nextTick } from 'vue'
const selector = '.el-message-box__wrapper'
@ -155,6 +156,7 @@ describe('MessageBox', () => {
})
await sleep();
(document.querySelector('.el-message-box__wrapper .el-button--primary') as HTMLButtonElement).click()
await nextTick()
await sleep()
expect(msgAction).toEqual('confirm')
})

View File

@ -219,12 +219,11 @@ export default defineComponent({
const confirmButtonClasses = computed(() => `el-button--primary ${ state.confirmButtonClass }`)
watch(() => state.inputValue, val => {
nextTick().then(() => {
if (state.type$ === 'prompt' && val !== null) {
validate()
}
})
watch(() => state.inputValue, async val => {
await nextTick()
if (state.type$ === 'prompt' && val !== null) {
validate()
}
}, { immediate: true })
watch(() => state.visible, val => {
@ -276,10 +275,10 @@ export default defineComponent({
function getSafeClose () {
const currentId = state.uid
return () => {
nextTick().then(() => {
if (currentId === state.uid) doClose()
})
return async () => {
await nextTick()
if (currentId === state.uid) doClose()
}
}