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

302
Views
how to automatically call discardPeriodicTasks after tests in Angular with jest?

I do a one time subscription that has a debounceTime pipe on my component onInit:

this.subscriptions.add(
  this.updateJobs$
    .pipe(
      filter(jobs => !!jobs.length),
      debounceTime(MyComponent.ListStabilizationTimeInMS),
      first(),
    )
    .subscribe((jobs: Update[]) => {
      // some code
    })
);

Because of this I need to include discardPeriodicTasks(); as last line after each fakeAsync tests, which I find tedious. Otherwise I get the error Error: 1 periodic timer(s) still in the queue. for all the tests.

I tried to create an afterEach:

afterEach(()=> {
  discardPeriodicTasks();
});

afterEach(fakeAsync(()=> {
  discardPeriodicTasks();
}));

But it does not work and the only way to pass the tests is to manually append discardPeriodicTasks(); to all the test cases. Would be great if it could be automated.

over 4 years ago · Santiago Trujillo
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!