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

126
Vistas
How can I import xhr-mock module right?

I have a problem with xhr-mock import (I'm using Jest framework). I have an exercise in which I must test a simple function that use XMLHttprequest. In order to do this I use the xhr-mock module and use 'setup' method in order to replace the global XMLHttpRequest object with the MockXMLHttpRequest. When I call 'setup' method from test I get the error: mockXHR.setup is not a function. Below there is my code.

const mockXHR = require('xhr-mock');
const { exampleFunction } = require('../function/exampleXHR');

describe('exampleXHR', () => {
    beforeEach(() => mockXHR.setup());

    test('xhr test', () => {
        exampleFunction();
    });

});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

For commonJS, use it like this:

var xhrMock = require("xhr-mock").default;

console.log(xhrMock.setup)

See: https://runkit.com/embed/gyrys612q3a2

about 4 years ago · Juan Pablo Isaza Denunciar
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