Menu
  • HOME
  • TAGS

Error: Invariant Violation: dangerouslyRenderMarkup(…): Cannot render markup in a worker thread

reactjs,mocha,jsdom,reactjs-testutils

The setup JSDOM setup was missing global.navigator. global.navigator = { userAgent: 'node.js' }; ...

Node.js - How can I edit elements in the jsdom window and save the window as a new HTML file?

javascript,jquery,html,node.js,jsdom

Here's an example of how to do it. I've based it on your code but simplified it a bit so that I'd have code that executes and illustrates how to do it. The following code reads foo.html and adds the text modified! to all p element and then writes it...

Using jsdom and Jest

javascript,angularjs,jsdom,jestjs

Because .env is probably asynchronous, the test will always exist before the callback is called. According to the jest tutorial, you can simply assign the HTML to document.body.innerHTML: // Set up our document body document.body.innerHTML = '<div>' + ' <span id="username" />' + ' <button id="button" />' + '</div>'; var...

Variable reference from external script in jsdom

javascript,node.js,jsdom

You need use win scope: console.log("exVar: ", win.exVar); and __dirname + "/exScript.js"

Use jQuery in Node without installing Python/VCBuild.exe

jquery,node.js,jsdom

I would suggest using cheerio Tiny, fast, and elegant implementation of core jQuery designed specifically for the server ...

React.render makes empty subcomponent in jsdom

javascript,node.js,reactjs,jsdom

When you do React.createElement(SubComponent, {}, "sub component"), you are passing "sub component" to SubComponent via this.props.children. However, in SubComponent, you're not using this.props.children and just rendering an empty div via React.createElement("div"). A simple fix would be to pass this.props.children to the div you're creating in the render method of SubComponent:...

How to use jQuery with [email protected]?

jquery,node.js,jsdom,io.js

It has nothing to do with iojs. The jsdom api can be used multiple ways, the following is more inline with what you are trying to do. Check out the repo // using Version 5.4.1 var jsdom = require('jsdom').jsdom; var document = jsdom('<html></html>', {}); var window = document.defaultView; var $...

JSDom Not Running Text as Scripts

javascript,node.js,jsdom

try observing what's in the "errors" object. from the documentation: If window creation succeeds and no s cause errors, then errors will be null, and window will be usable. Your issue will probably be revealed in there. =)...

jQuery find not working correctly in Node.js

javascript,jquery,node.js,jsdom

This works: var html = '<p class="widget">one</p><p class="widget">two</p><p class="widget">three</p>'; var jsdom = require('jsdom'); var jquery = require('jquery'); var document = jsdom.jsdom(html); var widgets = jquery(document.parentWindow)('.widget'); widgets.each(function() { console.log(this); }); What happens is that jquery() returns what in a browser would be accessible as window.jQuery. So you are calling jQuery.find, which...

Simulating click on document ReactJS/JSDom

javascript,unit-testing,reactjs,jsdom

Update: document.body.click will work in a browser, but for jsdom you need to manually create the event: document.body.addEventListener('click', function() { console.log('test'); }); var evt = document.createEvent("HTMLEvents"); evt.initEvent("click", false, true); document.body.dispatchEvent(evt) The above code is working for me in Jest and should work with "solo" jsdom as well....

Nodejs script fails to print after d3.json()?

node.js,d3.js,jsdom

Replace : setTimeout( fs.writeFileSync('map.svg', svgheader + window.d3.select("body").html()) , 10000 ); by setTimeout( function(){ fs.writeFileSync('map.svg', svgheader + window.d3.select("body").html()) } , 10000 ); ...

npm install persistent error ? (node-gyp build ?)

node.js,npm,jsdom,node-gyp,contextify

Seems I found a way by carefully deleting all node-related file and folder on my computer. 0. Context: I previously made several unsuccessful console clean-ups, with sudo apt-get remove --purge nodejs npm topojson followed by ~3 different ways to reinstall nodejs. I tried EACH way, from clean-up to reinstall, between...

How to get to the redirected page using Request and NodeJS

javascript,node.js,redirect,request,jsdom

Is it a non-GET request? Then you need to explicitly set followAllRedirects: true. followAllRedirects - follow non-GET HTTP 3xx responses as redirects (default: false) https://github.com/request/request (The docs for followRedirect are confusing because they don't seem to indicate that followRedirect only applies to GETs.)...

Passing by Reference on forEach

javascript,jquery,node.js,pass-by-reference,jsdom

You should use something like this to serialize the DOM: console.log(window.document.body.firstChild.outerHTML); As Bergi pointed out in the comments what jsdom manipulates is a DOM tree, jsdom won't go back to the source HTML and change that. What you have to do is serialize the DOM tree and you do this...

Nodejs parsing dom error with strict mode

jquery,node.js,jsdom

For me help reinstall jsdom from "latest" to old version "3.1.2" 1) Delete jsdom folder in node_modules 2) Change dependencies in package.json to: "jsdom": "3.1.2" 3) And of course run "npm install" Hope it's help you!...

how to parse a DOM with jsdom from a node REPL

javascript,node.js,dom,jsdom

jsdom.env callback gets evaluated asynchronously. This means that in most cases (probably always) console.log(x.window) gets executed before the x.window = window; assignment. The easiest fix is to pass a callback function that you execute after the assignment: ... function parse(html, x, done) { jsdom.env(html, function(errors, window) { x.window = window;...