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

199
Views
mocking callback in parameter

I have model setup like this

export class MyClass {
  grpcClient: MyGRPCClient;


  constructor(config: MyGRPCClientConfig) {
    this.grpcClient = new MyGRPCClient(
        config.serverUrl,
        grpc.credentials.createInsecure(),
    );
  }


  public methodA(): Promise<Array<String>> {
    return new Promise<Array<String>>((resolve, reject) => {
      this.grpcClient.methodGrpc(
          new MethodGrpcRequest(),
          (error, response) => { // <-- how to mock this (error, response) ?
            if (error) {
              reject(error);
            } else {
              resolve(response.getResult());
            }
          },
      );
    });
  }
}

In my test setup I want to mock grpcClient's outbound call so that when methodA() gets called, a new promise is returned and grpcClient's methodGrpc is mocked with what response I supply as part of test.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can try something like this- jest.mock('./MyGRPCClient',()=>({ methodGrpc: jest.fn() }));

about 4 years ago · Juan Pablo Isaza Report
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!