Node.js document is not defined
document
relates to the DOM (Document Object Model) in a web browser.
Node.js, however, is not a browser environment. It is a server environment, much like PHP or Perl, and as such, you can’t access the browser’s DOM or do anything specific to browser-hosted JavaScript.
The closest you could get is using something like browserify to include Node.js modules in your client-side code.
ReferenceError: document is not defined' error
The problem is you're require
ing the code that uses document
in the global scope before you declare the document.
var assert = require('assert');
var jsdom = require('mocha-jsdom');
global.document = jsdom();
var test = require('../index.js');
describe('Mutliply', function() { ...
should work, or even
var assert = require('assert');
var jsdom = require('mocha-jsdom');
global.document = jsdom();
describe('Mutliply', function() {
var test = require('../index.js'); // late import
it('should equal 9 when multiply is called', function() {
assert.equal(9, test.multiply());
});
});
Related Topics
Microsoft Cdn for Jquery or Google Cdn
Using Lodash .Groupby. How to Add Your Own Keys for Grouped Output
Jquery Function Not Binding to Newly Added Dom Elements
Map Isn't Showing on Google Maps JavaScript API V3 When Nested in a Div Tag
What Are Closures and Callbacks
What's the Yield Keyword in JavaScript
Executing JavaScript Without a Browser
How to Convert a String into a Math Operator in JavaScript
Why Do Arrow Functions Not Have the Arguments Array
How to Filter by Object Property in Angularjs
Contain Form Within a Bootstrap Popover
What's a Good Tool to Screen-Scrape with JavaScript Support
Google Bar Chart Cannot Change Individual Bar Color
Find All Text Nodes in HTML Page
Does JavaScript Process Using an Elastic Racetrack Algorithm