Replace $nextTick with flushPromises

This commit is contained in:
Pig Fang 2019-11-21 09:33:28 +08:00
parent 96c22e20af
commit 5df36ae8ea
20 changed files with 136 additions and 127 deletions

View File

@ -24,7 +24,7 @@ test('add player', async () => {
{ name: 'the-new' }
)
await flushPromises()
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.text()).not.toContain('the-new')
expect(Vue.prototype.$message.warning).toBeCalledWith('fail')

View File

@ -1,5 +1,6 @@
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import { flushPromises } from '../utils'
import ApplyToPlayerDialog from '@/components/ApplyToPlayerDialog.vue'
test('submit applying texture', async () => {
@ -35,7 +36,7 @@ test('submit applying texture', async () => {
cape: 1,
}
)
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$message.success).toBeCalledWith('ok')
})

View File

@ -51,11 +51,11 @@ test('rename texture', async () => {
.find('a')
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
button.trigger('click')
await flushPromises()
@ -79,11 +79,11 @@ test('remove texture', async () => {
.find('a')
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
button.trigger('click')
await flushPromises()
@ -105,15 +105,15 @@ test('set as avatar', async () => {
document.body.innerHTML += '<img alt="User Image" src="a">'
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
button.trigger('click')
await flushPromises()
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith('/user/profile/avatar', { tid: 1 })
expect(document.querySelector('img')!.src).toMatch(/\d+$/)
})

View File

@ -1,5 +1,6 @@
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import { flushPromises } from '../utils'
import EmailVerification from '@/components/EmailVerification.vue'
test('message box should not be render if verified', () => {
@ -17,10 +18,10 @@ test('resend email', async () => {
const button = wrapper.find('a')
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$message.error).toBeCalledWith('1')
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$message.success).toBeCalledWith('0')
})

View File

@ -66,7 +66,7 @@ test('install plugin', async () => {
{ name: 'd' }
)
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.text()).toContain('admin.enablePlugin')
})

View File

@ -28,7 +28,7 @@ test('change texture', async () => {
.mockResolvedValueOnce({ code: 0, message: '0' })
const wrapper = mount(Players)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.find('[data-test=changeTexture]')
wrapper
.findAll(Button)
@ -39,7 +39,7 @@ test('change texture', async () => {
.setValue('5')
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/players?action=texture',
{
@ -71,14 +71,14 @@ test('change player name', async () => {
return Promise.resolve({ value: 'new' } as MessageBoxData)
})
const wrapper = mount(Players)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.find('[data-test="name"]')
button.trigger('click')
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/players?action=name',
{ pid: 1, name: 'new' }
@ -102,14 +102,14 @@ test('change owner', async () => {
.mockResolvedValue({ value: '3' } as MessageBoxData)
const wrapper = mount(Players)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.find('[data-test="owner"]')
button.trigger('click')
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/players?action=owner',
{ pid: 1, uid: '3' }
@ -133,14 +133,14 @@ test('delete player', async () => {
.mockResolvedValue('confirm')
const wrapper = mount(Players)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.findAll(Button).at(1)
button.trigger('click')
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/players?action=delete',
{ pid: 1 }

View File

@ -16,7 +16,7 @@ test('basic render', async () => {
}],
})
const wrapper = mount(Reports)
await wrapper.vm.$nextTick()
await flushPromises()
const text = wrapper.text()
expect(text).toContain('a (UID: 1)')
expect(text).toContain('b (UID: 2)')
@ -29,7 +29,7 @@ test('link to skin library', async () => {
data: [{ id: 1, tid: 1 }],
})
const wrapper = mount(Reports)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('a').attributes('href')).toBe('/skinlib/show/1')
})
@ -41,7 +41,7 @@ test('delete texture', async () => {
code: 0, message: 'ok', data: { status: 1 },
})
const wrapper = mount(Reports)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.findAll('a').at(1)
button.trigger('click')
@ -65,7 +65,7 @@ test('ban uploader', async () => {
code: 0, message: 'ok', data: { status: 1 },
})
const wrapper = mount(Reports)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.findAll('a').at(2)
button.trigger('click')
@ -85,7 +85,7 @@ test('reject', async () => {
code: 0, message: 'ok', data: { status: 2 },
})
const wrapper = mount(Reports)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.find('button')
button.trigger('click')

View File

@ -31,7 +31,7 @@ test('humanize permission', async () => {
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
const text = wrapper.find('.vgt-table').text()
expect(text).toContain('admin.banned')
expect(text).toContain('admin.normal')
@ -46,7 +46,7 @@ test('generate players page link', async () => {
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-toggle="tooltip"]').attributes('href')).toBe('/admin/players?uid=1')
})
@ -57,7 +57,7 @@ test('permission option should not be displayed for super admins', async () => {
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-test=permission]').exists()).toBeFalse()
})
@ -70,7 +70,7 @@ test('permission option should be displayed for admin as super admin', async ()
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-test=permission]').exists()).toBeTrue()
})
@ -83,7 +83,7 @@ test('permission option should be displayed for normal users as super admin', as
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-test=permission]').exists()).toBeTrue()
})
@ -96,7 +96,7 @@ test('permission option should be displayed for banned users as super admin', as
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-test=permission]').exists()).toBeTrue()
})
@ -109,7 +109,7 @@ test('permission option should not be displayed for other admins as admin', asyn
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-test=permission]').exists()).toBeFalse()
})
@ -122,7 +122,7 @@ test('permission option should be displayed for normal users as admin', async ()
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-test=permission]').exists()).toBeTrue()
})
@ -135,7 +135,7 @@ test('permission option should be displayed for banned users as admin', async ()
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-test=permission]').exists()).toBeTrue()
})
@ -146,7 +146,7 @@ test('deletion button should not be displayed for super admins', async () => {
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-test="deleteUser"]').attributes('disabled')).toBe('disabled')
})
@ -159,7 +159,7 @@ test('deletion button should be displayed for admins as super admin', async () =
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-test="deleteUser"]').attributes('disabled')).toBeNil()
})
@ -172,7 +172,7 @@ test('deletion button should be displayed for normal users as super admin', asyn
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-test="deleteUser"]').attributes('disabled')).toBeNil()
})
@ -185,7 +185,7 @@ test('deletion button should be displayed for banned users as super admin', asyn
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-test="deleteUser"]').attributes('disabled')).toBeNil()
})
@ -198,7 +198,7 @@ test('deletion button should not be displayed for other admins as admin', async
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-test="deleteUser"]').attributes('disabled')).toBe('disabled')
})
@ -211,7 +211,7 @@ test('deletion button should be displayed for normal users as admin', async () =
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-test="deleteUser"]').attributes('disabled')).toBeNil()
})
@ -224,7 +224,7 @@ test('deletion button should be displayed for banned users as admin', async () =
],
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-test="deleteUser"]').attributes('disabled')).toBeNil()
})
@ -247,14 +247,14 @@ test('change email', async () => {
return Promise.resolve({ value: 'd@e.f' } as MessageBoxData)
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.find('[data-test="email"]')
button.trigger('click')
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/users?action=email',
{ uid: 1, email: 'd@e.f' }
@ -277,11 +277,11 @@ test('toggle verification', async () => {
.mockResolvedValueOnce({ code: 0, message: '0' })
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.find('[data-test="verification"')
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/users?action=verification',
{ uid: 1 }
@ -310,14 +310,14 @@ test('change nickname', async () => {
return Promise.resolve({ value: 'new' } as MessageBoxData)
})
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.find('[data-test="nickname"]')
button.trigger('click')
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/users?action=nickname',
{ uid: 1, nickname: 'new' }
@ -343,14 +343,14 @@ test('change password', async () => {
.mockResolvedValue({ value: 'password' }as MessageBoxData)
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.findAll(Button).at(0)
button.trigger('click')
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/users?action=password',
{ uid: 1, password: 'password' }
@ -378,14 +378,14 @@ test('change score', async () => {
.mockResolvedValue({ value: '45' }as MessageBoxData)
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.find('[data-test="score"]')
button.trigger('click')
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/users?action=score',
{ uid: 1, score: 45 }
@ -443,14 +443,14 @@ test('change permission', async () => {
})
let wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
let button = wrapper.find('[data-test=permission]')
button.trigger('click')
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/users?action=permission',
{ uid: 1, permission: 1 }
@ -458,7 +458,7 @@ test('change permission', async () => {
expect(wrapper.text()).toContain('admin.normal')
wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
button = wrapper.find('[data-test=permission]')
button.trigger('click')
@ -480,14 +480,14 @@ test('delete user', async () => {
.mockResolvedValue('confirm')
const wrapper = mount(Users)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.findAll(Button).at(1)
button.trigger('click')
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/admin/users?action=delete',
{ uid: 1 }

View File

@ -1,5 +1,6 @@
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import { flushPromises } from '../../utils'
import Login from '@/views/auth/Login.vue'
const Captcha = Vue.extend({
@ -35,7 +36,7 @@ test('login', async () => {
wrapper.find('input').setValue('a@b.c')
wrapper.find('[type="password"]').setValue('123')
form.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/auth/login',
{
@ -45,7 +46,7 @@ test('login', async () => {
expect(warning.text()).toBe('fail')
form.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$alert).toBeCalledWith('auth.tooManyFails.captcha', { type: 'error' })
expect(wrapper.find('img').exists()).toBeTrue()
@ -53,25 +54,25 @@ test('login', async () => {
recaptcha: 'sitekey', invisible: true, tooManyFails: false,
})
form.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
wrapper.setData({
recaptcha: 'sitekey', invisible: false, tooManyFails: false,
})
form.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$alert).toBeCalledWith('auth.tooManyFails.recaptcha', { type: 'error' })
wrapper.find('[type="checkbox"]').setChecked()
form.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/auth/login',
{
identification: 'a@b.c', password: '123', keep: true, captcha: 'a',
}
)
await wrapper.vm.$nextTick()
await flushPromises()
jest.runAllTimers()
expect(Vue.prototype.$message.success).toBeCalledWith('ok')
})

View File

@ -48,7 +48,7 @@ test('register', async () => {
wrapper.findAll('[type="text"]').at(0)
.setValue('abc')
form.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/auth/register',
{
@ -58,7 +58,7 @@ test('register', async () => {
captcha: 'captcha',
}
)
await wrapper.vm.$nextTick()
await flushPromises()
expect(warning.text()).toBe('fail')
form.trigger('submit')
@ -80,7 +80,7 @@ test('register with player name', async () => {
wrapper.findAll('[type="text"]').at(0)
.setValue('abc')
form.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/auth/register',
{

View File

@ -1,5 +1,6 @@
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import { flushPromises } from '../../utils'
import Reset from '@/views/auth/Reset.vue'
test('reset password', async () => {
@ -30,10 +31,10 @@ test('reset password', async () => {
'/auth/reset/1', // Ignore `location.search`
{ password: '12345678' }
)
await wrapper.vm.$nextTick()
await flushPromises()
expect(warning.text()).toBe('fail')
form.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$message.success).toBeCalledWith('ok')
})

View File

@ -2,6 +2,7 @@ import Vue from 'vue'
import { mount } from '@vue/test-utils'
// @ts-ignore
import Button from 'element-ui/lib/button'
import { flushPromises } from '../../utils'
import { queryString } from '@/scripts/utils'
import List from '@/views/skinlib/List.vue'
@ -135,7 +136,7 @@ test('check specified uploader', async () => {
},
})
const wrapper = mount(List)
await wrapper.vm.$nextTick()
await flushPromises()
const breadcrumb = wrapper.find('.breadcrumb')
const button = wrapper
.find('.advanced-filter')
@ -274,7 +275,7 @@ test('on like toggled', async () => {
onLikeToggled(tid: number, like: boolean): void,
items: Array<{ liked: boolean, likes: number }>
}>(List)
await wrapper.vm.$nextTick()
await flushPromises()
wrapper.vm.onLikeToggled(0, true)
expect(wrapper.vm.items[0].liked).toBeTrue()
expect(wrapper.vm.items[0].likes).toBe(1)

View File

@ -58,7 +58,7 @@ test('likes count indicator', async () => {
},
stubs: { previewer },
})
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('.likes').attributes('style')).toContain('color: rgb(224, 53, 59)')
expect(wrapper.find('.likes').text()).toContain('2')
})
@ -78,7 +78,7 @@ test('render basic information', async () => {
$route: ['/skinlib/show/1', '1'],
},
})
await wrapper.vm.$nextTick()
await flushPromises()
const text = wrapper.find('.box-primary').text()
expect(text).toContain('my-texture')
expect(text).toContain('alex')
@ -97,7 +97,7 @@ test('render action text of editing texture name', async () => {
$route: ['/skinlib/show/1', '1'],
},
})
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.contains('small')).toBeTrue()
Object.assign(window.blessing.extra, { currentUid: 2, admin: false })
@ -106,7 +106,7 @@ test('render action text of editing texture name', async () => {
$route: ['/skinlib/show/1', '1'],
},
})
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.contains('small')).toBeFalse()
})
@ -129,7 +129,7 @@ test('operation panel should not be rendered if user is anonymous', async () =>
$route: ['/skinlib/show/1', '1'],
},
})
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('.box-warning').exists()).toBeFalse()
})
@ -141,7 +141,7 @@ test('operation panel should not be rendered if not privileged', async () => {
$route: ['/skinlib/show/1', '1'],
},
})
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('.box-warning').exists()).toBeFalse()
})
@ -153,7 +153,7 @@ test('operation panel should be rendered if privileged', async () => {
$route: ['/skinlib/show/1', '1'],
},
})
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('.box-warning').exists()).toBeTrue()
})
@ -165,7 +165,7 @@ test('download texture', async () => {
$route: ['/skinlib/show/1', '1'],
},
})
await wrapper.vm.$nextTick()
await flushPromises()
wrapper.find('[data-test="download"]').trigger('click')
})
@ -177,7 +177,7 @@ test('link to downloading texture', async () => {
$route: ['/skinlib/show/1', '1'],
},
})
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('span[title="123"]').exists()).toBeTrue()
})
@ -190,7 +190,7 @@ test('set as avatar', async () => {
},
stubs: { previewer },
})
await wrapper.vm.$nextTick()
await flushPromises()
wrapper.find('[data-test="setAsAvatar"]').trigger('click')
expect(Vue.prototype.$confirm).toBeCalled()
})
@ -203,7 +203,7 @@ test('hide "set avatar" button when texture is cape', async () => {
},
stubs: { previewer },
})
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('[data-test="setAsAvatar"]').exists()).toBeFalse()
})
@ -471,6 +471,6 @@ test('truncate too long texture name', async () => {
$route: ['/skinlib/show/1', '1'],
},
})
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('.box-primary').text()).toContain('very-very-long-...')
})

View File

@ -1,12 +1,13 @@
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import { flushPromises } from '../../utils'
import Bind from '@/views/user/Bind.vue'
test('list existed players', async () => {
Vue.prototype.$http.get
.mockResolvedValue({ data: [{ name: 'a' }, { name: 'b' }] })
const wrapper = mount(Bind)
await wrapper.vm.$nextTick()
await flushPromises()
const options = wrapper.findAll('option')
expect(options).toHaveLength(2)
})
@ -14,7 +15,7 @@ test('list existed players', async () => {
test('show input box', async () => {
Vue.prototype.$http.get.mockResolvedValue({ data: [] })
const wrapper = mount(Bind)
await wrapper.vm.$nextTick()
await flushPromises()
const input = wrapper.find('input')
expect(input.exists()).toBeTrue()
})
@ -30,10 +31,10 @@ test('submit', async () => {
wrapper.find('input').setValue('abc')
form.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('.callout').text()).toBe('fail')
form.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$alert).toBeCalledWith('ok')
})

View File

@ -1,5 +1,6 @@
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import { flushPromises } from '../../utils'
import Closet from '@/views/user/Closet.vue'
import ClosetItem from '@/components/ClosetItem.vue'
import Previewer from '@/components/Previewer.vue'
@ -123,7 +124,7 @@ test('render items', async () => {
},
})
const wrapper = mount(Closet)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.findAll(ClosetItem)).toHaveLength(2)
})
@ -160,7 +161,7 @@ test('select texture', async () => {
const wrapper = mount<Vue & { skinUrl: string, capeUrl: string }>(Closet)
wrapper.setData({ skinItems: [{ tid: 1 }] })
wrapper.find(ClosetItem).vm.$emit('select')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.get).toBeCalledWith('/skinlib/info/1')
expect(wrapper.vm.skinUrl).toBe('/textures/a')
@ -168,7 +169,7 @@ test('select texture', async () => {
skinItems: [], capeItems: [{ tid: 2 }], category: 'cape',
})
wrapper.find(ClosetItem).vm.$emit('select')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.get).toBeCalledWith('/skinlib/info/2')
expect(wrapper.vm.capeUrl).toBe('/textures/b')
})
@ -193,7 +194,7 @@ test('apply texture', async () => {
expect(wrapper.find('.modal-body').text()).toContain('user.closet.use-as.empty')
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('input[type="radio"]').attributes('value')).toBe('1')
expect(wrapper.find('.model-label > img').attributes('src')).toBe('/avatar/35/10')
expect(wrapper.find('.modal-body').text()).toContain('name')
@ -233,8 +234,8 @@ test('select specified texture initially', async () => {
})
.mockResolvedValueOnce({ data: { type: 'cape', hash: '' } })
.mockResolvedValueOnce([])
const wrapper = mount(Closet)
mount(Closet)
jest.runAllTimers()
await wrapper.vm.$nextTick()
await flushPromises()
jest.unmock('@/scripts/utils')
})

View File

@ -2,6 +2,7 @@
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import { Button } from 'element-ui'
import { flushPromises } from '../../utils'
import Dashboard from '@/views/user/Dashboard.vue'
jest.mock('@tweenjs/tween.js', () => ({
@ -52,7 +53,7 @@ test('fetch score info', () => {
test('players usage', async () => {
Vue.prototype.$http.get.mockResolvedValue(scoreInfo())
const wrapper = mount(Dashboard)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.text()).toContain('3 / 15')
})
@ -70,18 +71,18 @@ test('storage usage', async () => {
},
}))
let wrapper = mount(Dashboard)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.text()).toContain('5 / 20 KB')
wrapper = mount(Dashboard)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.text()).toContain('2 / 4 MB')
})
test('display score', async () => {
Vue.prototype.$http.get.mockResolvedValue(scoreInfo())
const wrapper = mount(Dashboard)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('#score').text()).toContain('835')
})
@ -96,19 +97,19 @@ test('button `sign` state', async () => {
.mockResolvedValueOnce(scoreInfo({ user: { lastSignAt: Date.now() } }))
let wrapper = mount(Dashboard)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find(Button).attributes('disabled')).toBeNil()
wrapper = mount(Dashboard)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find(Button).attributes('disabled')).toBe('disabled')
wrapper = mount(Dashboard)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find(Button).attributes('disabled')).toBeNil()
wrapper = mount(Dashboard)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find(Button).attributes('disabled')).toBe('disabled')
})
@ -125,12 +126,12 @@ test('remaining time', async () => {
}))
let wrapper = mount(Dashboard)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find(Button).text()).toMatch(/(29)|(30)/)
expect(wrapper.find(Button).text()).toContain('min')
wrapper = mount(Dashboard)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find(Button).text()).toContain('23')
expect(wrapper.find(Button).text()).toContain('hour')
@ -154,15 +155,15 @@ test('sign', async () => {
})
const wrapper = mount(Dashboard)
const button = wrapper.find(Button)
await wrapper.vm.$nextTick()
await flushPromises()
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith('/user/sign')
expect(Vue.prototype.$message.warning).toBeCalledWith('1')
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(button.attributes('disabled')).toBe('disabled')
expect(wrapper.text()).toContain('3 / 4 KB')
})

View File

@ -15,7 +15,7 @@ test('basic render', async () => {
{ id: 1 },
])
const wrapper = mount(OAuth)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.findAll('[data-test=remove]')).toHaveLength(1)
})
@ -26,7 +26,7 @@ test('create app', async () => {
.mockResolvedValueOnce({ message: 'fail' })
.mockResolvedValueOnce({ id: 1, name: 'name' })
const wrapper = mount(OAuth)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.find('[data-test=create]')
const inputs = wrapper.findAll('.value')
@ -36,7 +36,7 @@ test('create app', async () => {
.setValue('https://example.com/')
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/oauth/clients',
{ name: 'name', redirect: 'https://example.com/' }
@ -44,7 +44,7 @@ test('create app', async () => {
expect(Vue.prototype.$message.warning).toBeCalledWith('fail')
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.text()).toContain('name')
})
@ -59,11 +59,11 @@ test('modify name', async () => {
.mockRejectedValueOnce('')
.mockResolvedValue({ value: 'new-name' } as MessageBoxData)
const wrapper = mount(OAuth)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.find('[data-test=name]')
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(walkFetch).not.toBeCalled()
button.trigger('click')
@ -93,11 +93,11 @@ test('modify redirect', async () => {
.mockRejectedValueOnce('')
.mockResolvedValue({ value: 'https://example.net/' } as MessageBoxData)
const wrapper = mount(OAuth)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.find('[data-test=callback]')
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(walkFetch).not.toBeCalled()
button.trigger('click')
@ -125,7 +125,7 @@ test('remove app', async () => {
.mockResolvedValue('confirm')
const wrapper = mount(OAuth)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.find('[data-test=remove]')
button.trigger('click')

View File

@ -58,7 +58,7 @@ test('click to preview player', async () => {
.mockResolvedValueOnce({ data: { hash: 'c' } })
.mockResolvedValueOnce({ data: { hash: 'd' } })
const wrapper = mount(Players)
await wrapper.vm.$nextTick()
await flushPromises()
wrapper.find('tbody > tr:nth-child(1)').trigger('click')
await flushPromises()
@ -100,7 +100,7 @@ test('change player name', async () => {
return Promise.resolve({ value: 'new-name' } as MessageBoxData)
})
const wrapper = mount(Players)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.findAll(Button).at(0)
button.trigger('click')
@ -131,7 +131,7 @@ test('delete player', async () => {
.mockRejectedValueOnce({})
.mockResolvedValue('confirm')
const wrapper = mount(Players)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.findAll(Button).at(2)
button.trigger('click')
@ -183,7 +183,7 @@ test('clear texture', async () => {
.mockResolvedValueOnce({ code: 1 })
.mockResolvedValue({ code: 0, message: 'ok' })
const wrapper = mount(Players)
await wrapper.vm.$nextTick()
await flushPromises()
const button = wrapper.find('[data-test=clearTexture]')
wrapper.find('.player').trigger('click')

View File

@ -32,7 +32,7 @@ test('reset avatar', async () => {
expect(Vue.prototype.$http.post).not.toBeCalled()
button.trigger('click')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/user/profile/avatar',
{ tid: 0 }
@ -58,7 +58,7 @@ test('change password', async () => {
wrapper.setData({ confirmPassword: '1' })
form.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/user/profile?action=password',
{ current_password: '1', new_password: '1' }
@ -66,7 +66,7 @@ test('change password', async () => {
expect(Vue.prototype.$alert).toBeCalledWith('w', { type: 'warning' })
form.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$alert).toBeCalledWith('o')
})
@ -87,12 +87,12 @@ test('change nickname', async () => {
expect(Vue.prototype.$confirm).toBeCalledWith('user.changeNickName')
form.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/user/profile?action=nickname',
{ new_nickname: 'nickname' }
)
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$alert).toBeCalledWith('w', { type: 'warning' })
form.trigger('submit')
@ -117,12 +117,12 @@ test('change email', async () => {
expect(Vue.prototype.$http.post).not.toBeCalled()
form.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$http.post).toBeCalledWith(
'/user/profile?action=email',
{ new_email: 'a@b.c', password: 'abc' }
)
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$alert).toBeCalledWith('w', { type: 'warning' })
form.trigger('submit')
@ -144,10 +144,10 @@ test('delete account', async () => {
'/user/profile?action=delete',
{ password: 'abc' }
)
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$alert).toBeCalledWith('w', { type: 'warning' })
form.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
expect(Vue.prototype.$alert).toBeCalledWith('o', { type: 'success' })
})

View File

@ -1,5 +1,6 @@
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import { flushPromises } from '../../utils'
import Report from '@/views/user/Report.vue'
test('basic render', async () => {
@ -9,7 +10,7 @@ test('basic render', async () => {
},
])
const wrapper = mount(Report)
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('a').attributes('href')).toBe('/skinlib/show/1')
expect(wrapper.text()).toContain('report.status.1')