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

120
Views
How to stub cross-fetch with sinon

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.

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!