diff --git a/resources/assets/tests/components/user/ClosetItem.test.js b/resources/assets/tests/components/user/ClosetItem.test.js index 6ecee627..3866383c 100644 --- a/resources/assets/tests/components/user/ClosetItem.test.js +++ b/resources/assets/tests/components/user/ClosetItem.test.js @@ -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"]'); }); diff --git a/resources/assets/tests/components/user/Profile.test.js b/resources/assets/tests/components/user/Profile.test.js index 0b10153d..dc901a4e 100644 --- a/resources/assets/tests/components/user/Profile.test.js +++ b/resources/assets/tests/components/user/Profile.test.js @@ -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' }); }); diff --git a/resources/assets/tests/utils.js b/resources/assets/tests/utils.js new file mode 100644 index 00000000..b7087821 --- /dev/null +++ b/resources/assets/tests/utils.js @@ -0,0 +1,3 @@ +export function flushPromises() { + return new Promise(resolve => setImmediate(resolve)); +}