I have the next code:
async function(paramA?: string): Promise<void> {
if (paramA === undefined) {
paramA = this.randomString();
}
this.funnel.loginFunnel(Status.Pending);
await this.tracker.flush();
this.service.call(this.name, paramA, code);
}
And I want test that loginFunnel is called with status pending, and the service is call with the paramA, but this classes are initialized in constructor:
constructor(params: Params) {
this.tracker = new Tracker(params);
this.service = new Service(params, this.tracker);
}
So how I can spy on with jest?, this is only javascript, not React or similar.
I try a lot of things, but I don't know how do...
The last try was this, import Tracker class from his path...
jest.mock('../tracker');
service.call();
expect(Tracker).toHaveBeenCalledTimes(1);
But I got this answer from test:
expect(received).toHaveBeenCalledTimes(expected)
Matcher error: received value must be a mock or spy function
Received has type: function
Received has value: [Function Tracker]