In my node project I'm using Sinon and I'm having issues with mocking cross-fetch lib.
So basically I have a simple service which is calling cross-fetch internally something more or less like this:
import fetch from 'cross-fetch';
public async sendMyData(id): Promise<void> {
const payload = await this.generatePayload(id);
await sendRequest(payload, id);
}
And then fetch is called like this:
private async sendRequest(payload, id): Promise<void> {
await fetch(`http://my-api-url/endpoint/${id}`, {
method: 'POST',
body: JSON.stringify(payload)
});
}
So in my tests I want to create my service and mock cross-fetch and inspect with what payload it has been called.