'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();
});
});
Solution 1:[1]
For commonJS, use it like this:
var xhrMock = require("xhr-mock").default;
console.log(xhrMock.setup)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | slideshowp2 |
