With jest, is there a way to mock a promise that never resolves? I want to write a snapshot test where I verify my UI in a loading state. The loading state depends on a promise. If the promise resolves, the loading state goes away.
Template:
<div v-if="isLoading">
<div>Starting service, please wait</div>
</div>
Script:
async startService() {
try {
this.isLoading = true;
const response = await this.service.start();
this.isLoading = false;
}
Proposed test:
it('loading screen should display', async() => {
const startServiceSpy = jest
.spyOn(Service.prototype, 'start')
.mockImplementation(() =>
DO NOT RESOLVE SERVICE CALL HERE
}));
await wrapper.vm.startService();
// show loading screen in snapshot
expect(wrapper.html()).toMatchSnapshot();
});