How can I import xhr-mock module right?

Viewed 63

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();
    });

});
1 Answers
Related