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

200
Views
How to mock function responses in test

I have these functions in my Typescript application:

getDocStatus(p: string): Promise<boolean> {
    return Api.getData(this.apiUrl + this.checkDoc + p).then(
        (response) => response.data
    );
}

getExpired(p: string): Promise<boolean> {
    return Api.getData(this.apiUrl + this.checkExpired + p).then(
        (response) => response.data
    );
}

async getButtonStatus(p: string) {
    const docStatus = this.getDocStatus(p);
    const expiredStatus = this.getExpired(p);
    if (await docStatus === Boolean(false) && await expiredStatus === Boolean(false)) {
        return false;
    } else {
        return true;
    }
}

I'm now trying to write a test for getButtonStatus. In the test I want to mock response values for getDocStatus and getExpired. How can I do that?

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!