window-mock
window-mock copied to clipboard
new WindowMock() is not a constructor
Hi @sbstnmsch,
I search a lib to mock window and document object into a Webpack config file and I found your lib. My webpack file is write into Javascript ES5, like below :
const path = require('path');
const webpack = require('webpack');
const WindowMock = require('window-mock');
const fakeWindow = new WindowMock();
...
new webpack.DefinePlugin({
window: fakeWindow,
document: fakeWindow.document,
location: JSON.stringify({
protocol: 'https',
host: `localhost`
})
})
I set my constant fakeWindow as your example into README : var windowMock = new WindowMock();
but I keep a error on build: TypeError: WindowMock is not a constructor
Environments :
"webpack": "^4.20.2",
"window-mock": "^0.0.13"
Hi,
When looking into the code WindowMock
is exported as exports.default = WindowMock;
.
In ES6 it is interpreted as a named export, so in order to access the default export you need to:
const WindowMock = require('window-mock').default;
Hope it helps.
@khylias sorry I completely missed this issue. And thanks to @teef for clarification!