Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
Mock promise that never resolves with Jest

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
    }));

  wrapper.vm.startService();

  // show loading screen in snapshot
  expect(wrapper.html()).toMatchSnapshot();

});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!