N
Nuxt7mo ago
Tumulte

registerEndpoint requires multiple flushPromises

registerEndpoint('/api/channel/1', {
method: 'DELETE',
handler: () => {
return {};
},
});

describe('ChannelMenu', () => {
it('deletes a channel', async () => {
const wrapper = mountWrapper();
const deleteState = useState(DELETE_CHANNEL_ID);
wrapper.vm.deleteChannel();
await flushPromises();
await flushPromises();

expect(deleteState.value).toBe(wrapper.vm.props.channel.idChannel);
});
});
registerEndpoint('/api/channel/1', {
method: 'DELETE',
handler: () => {
return {};
},
});

describe('ChannelMenu', () => {
it('deletes a channel', async () => {
const wrapper = mountWrapper();
const deleteState = useState(DELETE_CHANNEL_ID);
wrapper.vm.deleteChannel();
await flushPromises();
await flushPromises();

expect(deleteState.value).toBe(wrapper.vm.props.channel.idChannel);
});
});
take this code for instance... if I only use 1 flushPromises, the expect won't work. Is it expected ? Is there a workaround ? thanks !
1 Reply
Tumulte
TumulteOP7mo ago
the solution is to return $fetch in deleteChannel() and await wrapper.vm.deleteChannel()
Want results from more Discord servers?
Add your server