Created
February 9, 2018 19:45
-
-
Save dsadhanala/d0cd8b84f791b40433c7636dd9dbbc01 to your computer and use it in GitHub Desktop.
setup browser env in node with JSDOM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// setup browser env | |
const jsdom = require("jsdom@11.5.1"); | |
const { JSDOM } = jsdom; | |
const doc = new JSDOM(`<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>`); | |
global.window = doc.window; | |
global.document = window.document; | |
// mock missing api | |
document.importNode = (node, deep) => node.cloneNode(deep); | |
global.requestAnimationFrame = (callback) => setTimeout(callback, 0); | |
// setup chai | |
const { expect, should, assert } = require('chai'); | |
global.expect = expect; | |
global.should = should; | |
global.assert = assert; | |
var hyperHTML = require("hyperhtml"); | |
const cssClassName = 'test-class'; | |
hyperHTML.bind(document.body)`<div class="${cssClassName}"></div>`; | |
document.toString(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment