node.js - NodeJS Global, JSdom, Unit test -


this simple question:

when use create dom jsdom:

const dom = (html = '<!doctype html><body></body></html>') => {   const domobject = new jsdom(html);   const { window } = domobject;   const { document } = (domobject).window;    global.window = window;   global.document = document;   global.navigator = {     useragent: 'jsdom',     language: 'en'   }; }  module.exports = dom; 

and use on test such:

import test 'tape'; import dom 'dom';  // create global dom dom(); 

and yet when test have document, window , navigator undefined in tests. it's strange, missing something? or making assumption on it's behavior. should approach differently? if how?

thanks!

and how it's done!

http://airbnb.io/enzyme/docs/guides/jsdom.html

worked beautifully, curious.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -