Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda