I have a model setup in the following way:
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 testing environment, I need to mock the outbound call of grpcClient
so that when methodA()
is called, a new promise is returned and grpcClient
's methodGrpc
is mocked with the response I provide as part of the test.