FAQ Database Discussion Community


JSDom Not Running Text as Scripts

javascript,node.js,jsdom
According to the JSDom README, you can pass an array of Javascript Strings to execute, but it seems like this feature isn't working for me. This is my node app: var fs = require('fs'); var jsdom = require('jsdom-no-contextify'); var scripts = ['manipulate-dom.js']; var src = scripts.map(function(filename) { return fs.readFileSync(filename, 'utf8');...

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

node.js,d3.js,jsdom
(Edit: the question have been rewritten to better isolate the issue.) I'am writing a single D3js script.js which could be reused "as it" in both web browser for client side and nodejs for server side uses. I made some good progress : a single d3js script.js indeed create basic svg...

How to use jQuery with [email protected]?

jquery,node.js,jsdom,io.js
I am migrating from node.js to io.js and my old node.js code does not work with [email protected] var jsdom=require('jsdom'); var $=require('jquery')(jsdom.jsdom().createWindow); Here is the error: /tmp/iojs/node_modules/jquery/dist/jquery.js:28 if ( !w.document ) { ^ TypeError: Cannot read property 'document' of undefined at module.exports (/tmp/iojs/node_modules/jquery/dist/jquery.js:28:12) at Object.<anonymous> (/tmp/iojs/test.js:2:24) at Module._compile (module.js:431:26) at Object.Module._extensions..js...

How to get to the redirected page using Request and NodeJS

javascript,node.js,redirect,request,jsdom
I am using Request, Jsdom and NodeJS to log in to a webpage. According to the Request api, followRedirect - follow HTTP 3xx responses as redirects (default: true). This property can also be implemented as function which gets response object as a single argument and should return true if redirects...

Nodejs parsing dom error with strict mode

jquery,node.js,jsdom
I am really new to nodejs, and i am putting myself through a crash course these 3-4 days to get a bit better at it... Trying to run this code: (function () { var jsdom = require('jsdom'); jsdom.env({ html: '<html><body><h1>Hello World!</h1><p class="hello">Heya Big World!</body></html>' //scripts: [ //'http://code.jquery.com/jquery-1.5.min.js' //] }, function...

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
I want to load an HTML file (using fs.read), load the DOM using jsdom, and then change the text of the nodes of the body (via jquery). Then I want to save the edited DOM window as an HTML file. Is there a way to do this? The code I...

Using jsdom and Jest

javascript,angularjs,jsdom,jestjs
I'm experimenting with Jest to unit test an angular application. In order to test the angular bindings I'm trying to use jsdom (N.B. I'm using v3.1.2 as I'm using node not IO). When I need to load a script with the html the test seems to complete before the script...

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

reactjs,mocha,jsdom,reactjs-testutils
React Tests Fails after set State causes second render Up until now testing has been going well with JSDOM and Mocha. So far have not had to test any components that change their state. I found my first issue testing a component that changes it's state. The Error 1) Reduced...

React.render makes empty subcomponent in jsdom

javascript,node.js,reactjs,jsdom
I'm playing with React in node using jsdom. When I try to render a component that contains another component that has content, it'll fail to render the subcomponents content. For example, var React = require('react'); var SubComponent = React.createClass({ render: function() { return React.createElement("div"); } }); var TestComponent = React.createClass({...

how to parse a DOM with jsdom from a node REPL

javascript,node.js,dom,jsdom
I am trying to write some DOM-parsing code to run from a node REPL environment. Below is a SSCCE: "use strict"; var jsdom = require("jsdom"); var html="<a></a>"; function parse(html, x) { jsdom.env(html, function(errors, window) { x.window = window; }); } var x = {}; parse(html, x); console.log(x.window); The idea being...