mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2025-01-06 13:34:50 +08:00
Add flushPromises
for tests
This commit is contained in:
parent
5e4bc4b564
commit
8a83a176ce
@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils';
|
||||
import { flushPromises } from '../../utils';
|
||||
import ClosetItem from '@/components/user/ClosetItem';
|
||||
import axios from 'axios';
|
||||
import { swal } from '@/js/notify';
|
||||
@ -86,9 +87,7 @@ test('remove texture', async () => {
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
button.trigger('click');
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
await wrapper.vm.$nextTick();
|
||||
await flushPromises();
|
||||
expect(wrapper.emitted()['item-removed'][0][0]).toBe(1);
|
||||
expect(axios.post).toBeCalledWith('/user/closet/remove', { tid: 1 });
|
||||
});
|
||||
@ -117,9 +116,7 @@ test('set as avatar', async () => {
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
button.trigger('click');
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
await wrapper.vm.$nextTick();
|
||||
await flushPromises();
|
||||
expect(axios.post).toBeCalledWith('/user/profile/avatar', { tid: 1 });
|
||||
expect(window.$).toBeCalledWith('[alt="User Image"]');
|
||||
});
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { mount } from '@vue/test-utils';
|
||||
import { flushPromises } from '../../utils';
|
||||
import Profile from '@/components/user/Profile';
|
||||
import axios from 'axios';
|
||||
import toastr from 'toastr';
|
||||
@ -102,8 +103,7 @@ test('change nickname', async () => {
|
||||
expect(swal).toBeCalledWith({ type: 'warning', html: 'w' });
|
||||
|
||||
button.trigger('click');
|
||||
await wrapper.vm.$nextTick();
|
||||
await wrapper.vm.$nextTick();
|
||||
await flushPromises();
|
||||
expect(swal).toBeCalledWith({ type: 'success', html: 'o' });
|
||||
});
|
||||
|
||||
@ -146,8 +146,7 @@ test('change email', async () => {
|
||||
expect(swal).toBeCalledWith({ type: 'warning', text: 'w' });
|
||||
|
||||
button.trigger('click');
|
||||
await wrapper.vm.$nextTick();
|
||||
await wrapper.vm.$nextTick(); // There are two promises, so call it twice.
|
||||
await flushPromises();
|
||||
expect(swal).toBeCalledWith({ type: 'success', text: 'o' });
|
||||
});
|
||||
|
||||
|
3
resources/assets/tests/utils.js
Normal file
3
resources/assets/tests/utils.js
Normal file
@ -0,0 +1,3 @@
|
||||
export function flushPromises() {
|
||||
return new Promise(resolve => setImmediate(resolve));
|
||||
}
|
Loading…
Reference in New Issue
Block a user