ReferenceError: HTMLElement is not defined
See original GitHub issueHello, I’m using Webstorm to run Mocha tests (on react components) using Chai together with Enzyme, Sinon and Sinon-chai.
I’m doing something like this:
expect(ChildSpy).to.have.been.calledWithMatch({a:'a', b: 'b'});
that basically is the same as saying:
sinon.assert.calledWith(ChildSpy, sinon.match({a:'a', b: 'b'}));
.
However I use it I receive and exception from this packages, exactly from this line:
ReferenceError: HTMLElement is not defined
at typeDetect (node_modules/type-detect/index.js:159:24)
at typeOf (node_modules/sinon/lib/sinon/util/core/typeOf.js:6:12)
at Object.match (node_modules/sinon/lib/sinon/match.js:103:16)
at Context.<anonymous> (test/main.js:106:45)
Apparently the HTMLElement
used in this function is not defined.
Does that depend on the node version or maybe was this package conceived to run in the browser and not in node?
if (obj instanceof HTMLElement && obj.tagName === 'BLOCKQUOTE') {
return 'HTMLQuoteElement';
}
Maybe there is a check somewhere to understand if we are in a browser or not but I could have make things difficult to check because before starting my tests I do this:
// Setup for enzyme: http://airbnb.io/enzyme/docs/guides/jsdom.html
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>', {
url: 'http://localhost'
});
const win = doc.defaultView;
// Setup for react test-utils 'renderIntoDocument':
// it requires window, window.document and window.document.createElement
// globally available before you can import React
global.document = doc;
global.window = win;
global.navigator = win.navigator;
So type-detect believes is in a browser when in fact it’s not? 🤔
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:8
This worked for me when i declared JSDOM in a separate file and use require with mocha
Temp fix until #91 will be solved: