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

220
Views
Canceling a mocked function in Jest and getting the original behavior after a single call
jest.mock("./MyService");
class MyService{
    async f1(args) {
        let out= await this.f2(args);
        ...
    }
}
...
// my test code:
MyService.f1.mockResolvedValueOnce([]);
await OtherService.f3(); // f1 is mocked and called in f3 and returns [] (everything is fine)
MyService.f1.mockRestore(); // trying to forget mocking f1 and getting the original behavior
MyService.f2.mockResolvedValueOnce([some data]); // I want original f1 to be called and mock the inner f2 but f1 is never called and I get undefined output from it

I'm trying to mock MyService's functions only occasionally and after using the mocked version, forget that mocking and get the original behavior of them. But when I do it for once and restore that mock, I get undefined for the output of the mocked function and it's actually never called.

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!