test(loading-bar): fix error (#1434)

This commit is contained in:
XieZongChen 2021-10-25 05:10:57 -05:00 committed by GitHub
parent f618ffc167
commit 334b87d475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 30 deletions

View File

@ -105,7 +105,7 @@ export default defineComponent({
class={`${clsPrefix}-color-picker-swatch`}
tabindex={0}
onClick={() => this.handleSwatchSelect(swatch)}
onKeydown={e => this.handleSwatchKeyDown(e, swatch)}
onKeydown={(e) => this.handleSwatchKeyDown(e, swatch)}
>
<div
class={`${clsPrefix}-color-picker-swatch__fill`}

View File

@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils'
import { defineComponent, h, nextTick } from 'vue'
import { defineComponent, h } from 'vue'
import { NLoadingBarProvider, useLoadingBar } from '../index'
const Provider = defineComponent({
@ -13,7 +13,7 @@ describe('n-loading-bar', () => {
mount(NLoadingBarProvider)
})
it('should have start type', () => {
it('should have start type', (done) => {
const Test = defineComponent({
setup () {
const loadingBar = useLoadingBar()
@ -26,17 +26,21 @@ describe('n-loading-bar', () => {
const wrapper = mount(() => (
<Provider>{{ default: () => <Test /> }}</Provider>
))
void nextTick(() => {
setTimeout(() => {
expect(document.querySelector('.n-loading-bar')).not.toEqual(null)
wrapper.unmount()
})
done()
}, 0)
})
it('should have finish type', async () => {
it('should have finish type', (done) => {
const Test = defineComponent({
setup () {
const loadingBar = useLoadingBar()
loadingBar.start()
loadingBar.finish()
setTimeout(() => {
loadingBar.finish()
}, 0)
},
render () {
return null
@ -45,14 +49,16 @@ describe('n-loading-bar', () => {
const wrapper = mount(() => (
<Provider>{{ default: () => <Test /> }}</Provider>
))
await nextTick()
expect(document.querySelector('.n-loading-bar--finishing')).not.toEqual(
null
)
wrapper.unmount()
setTimeout(() => {
expect(document.querySelector('.n-loading-bar--finishing')).not.toEqual(
null
)
wrapper.unmount()
done()
}, 0)
})
it('should have error type', async () => {
it('should have error type', () => {
const Test = defineComponent({
setup () {
const loadingBar = useLoadingBar()
@ -65,14 +71,10 @@ describe('n-loading-bar', () => {
const wrapper = mount(() => (
<Provider>{{ default: () => <Test /> }}</Provider>
))
await nextTick(() => {
setTimeout(() => {
expect(document.querySelector('.n-loading-bar--error')).not.toEqual(
null
)
wrapper.unmount()
}, 300)
})
setTimeout(() => {
expect(document.querySelector('.n-loading-bar--error')).not.toEqual(null)
wrapper.unmount()
}, 0)
})
it('should have loadingBarStyle prop', (done) => {
@ -98,14 +100,12 @@ describe('n-loading-bar', () => {
default: () => <Test />
}
})
void nextTick(() => {
setTimeout(() => {
expect(
document.querySelector('.n-loading-bar--error')?.getAttribute('style')
).toContain('height: 5px;')
wrapper.unmount()
done()
}, 300)
})
setTimeout(() => {
expect(
document.querySelector('.n-loading-bar--error')?.getAttribute('style')
).toContain('height: 5px;')
wrapper.unmount()
done()
}, 0)
})
})