jsdom

Does Jest reset the JSDOM document after every suite or test?

天涯浪子 提交于 2019-12-03 12:30:22
I'm testing a couple of components that reach outside of their DOM structure when mounting and unmounting to provide specific interaction capability that wouldn't be possible otherwise. I'm using Jest and the default JSDOM initialization to create a browser-like environment within node. I couldn't find anything in the documentation to suggest that Jest reset JSDOM after every test execution, and there's no explicit documentation on how to do that manually if that is not the case. My question is, does Jest reset the JSDOM instance after every test, suite or does it keep a single instance of

Testing React portals with enzyme

≡放荡痞女 提交于 2019-12-03 11:41:26
So I'm having a hard time writing tests for a modal component using React fiber's portal. Because my modal mounts to a domNode on the root of the <body /> but because that domNode doesn't exist, the test fails. Some code to give, context: index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="theme-color" content="#000000"> <link rel="manifest" href="%PUBLIC_URL%/manifest.json"> <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> <title>React App</title> </head> <body>

Node Jsdom Scrape Google's Reverse Image Search

[亡魂溺海] 提交于 2019-12-03 08:55:00
I want to programatically find a list of URLs for similar images given an image URL. I can't find any free image search APIs so I'm trying to do this by scraping Google's Search by Image . If I have an image URL, say http://i.imgur.com/oLmwq.png , then navigating to https://www.google.com/searchbyimage?&image_url=http://i.imgur.com/oLmwq.png gives related images and info. How do I get jsdom.env to produce the HTML your browser gets from the above URL? Here's what I've tried ( CoffeeScript ): jsdom = require 'jsdom' url = 'https://www.google.com/searchbyimage?&image_url=http://i.imgur.com/oLmwq

Building contextify under Windows 7 x64 (for NodeJS jQuery)

对着背影说爱祢 提交于 2019-12-03 05:19:05
I try to get node-jquery working. contextify is one of the dependencies (required for jsdom ). contextify needs to be built somehow using Python. But this does not seem to work on Windows 7 x64. At least one my computer :) After some readings ( #10 , #12 , #17 ) and trying some binaries provided by this fork and this one I can get it work ... I've got the same error from node-gyp configure or from node-gyp rebuild ( npm install jquery ) : info it worked if it ends with ok info downloading: http://nodejs.org/dist/v0.6.14/node-v0.6.14.tar.gz info downloading: http://nodejs.org/dist/v0.6.14/x64

error 'document' is not defined : eslint / React

天大地大妈咪最大 提交于 2019-12-03 04:34:17
I'm building a React app, with create-react-app. I got the following error when running ESLint: 8:3 error 'document' is not defined no-undef. My app runs without error, but I got this ESLint error in 2 files. See one of those .jsx files and my ESLint configuration. index.jsx: import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; import './index.css'; ReactDOM.render( <App />, document.getElementById('root'), ); eslintrc.js: module.exports = { "extends": "airbnb", "plugins": [ "react", "jsx-a11y", "import" ], "env": { "jest": true } }; How can I fix this ? For

I want to run d3 from a Cakefile

非 Y 不嫁゛ 提交于 2019-12-03 03:46:27
I'd like to execute some d3 code from the command line. Initially I just tried something like: task 'data', 'Build some data with d3', -> d3 = require('lib/d3.v2') console.log "d3 version = "+ d3.version But this didn't work. I got errors like this: node.js:201 throw e; // process.nextTick error, or 'error' event on first tick ^ ReferenceError: CSSStyleDeclaration is not defined at /Users/mydir/Documents/classes/middleclass/app/lib/d3.min.js:1:21272 at Object.<anonymous> (/Users/mydir/Documents/classes/middleclass/app/lib/d3.min.js:2:25395) at Module._compile (module.js:432:26) at Object..js

Server-Side HighStock charts generation with NodeJS

放肆的年华 提交于 2019-12-03 03:18:06
I'm using HighStock to generate some charts in browser. But now I want to store some of them at the server. So I know that HighCharts can be exported to the server but I'd rather use some other way if possible. The thing is to run HighStock at the server and convert the svg to some image format and then store it there. Quick googling gives me this page . Combining HighCharts and NodeJS seems to be the right way but this solution does not work for newer versions of HighCharts. More precisely, using jsdom module (v0.2.10 - the latest) in NodeJS with HighStock v1.0.2 (look at the following code):

Rickshaw CSS/Axes in JSDOM

烂漫一生 提交于 2019-12-02 18:20:48
问题 I'm using Node on a server side application, to dynamically produce graphs. I'm using d3.js and rickshaw.js to create SVG versions of the graph, and imagemagick to convert that SVG into a png. I am using JSDOM as my DOM. I am getting this error: https://github.com/shutterstock/rickshaw/issues/186 The solution given here is to pull in the css, I found an answer on stack overflow on how to do this with JSDOM: How do you ad stylesheets to JSDOM So I've followed these instructions, and pulled in

What are the use cases of jsdom

大城市里の小女人 提交于 2019-12-02 17:55:01
After reading this Micro templates are dead article. I've become curious: Whether Using the DOM on the server results in cleaner more maintainable code then templating. Whether it's more efficient to use jsdom instead of a templating engine. How to factor jsdom into the View of a standard MVC setup. And generally in what situations would it be better to use a server-side DOM abstraction, like jsdom rather then a templating engine, like EJS or jade . The question is specific to node.js and other SSJS Its a nice abstraction that matches a client side engineers take on how the dom is built and

Rickshaw CSS/Axes in JSDOM

☆樱花仙子☆ 提交于 2019-12-02 07:49:10
I'm using Node on a server side application, to dynamically produce graphs. I'm using d3.js and rickshaw.js to create SVG versions of the graph, and imagemagick to convert that SVG into a png. I am using JSDOM as my DOM. I am getting this error: https://github.com/shutterstock/rickshaw/issues/186 The solution given here is to pull in the css, I found an answer on stack overflow on how to do this with JSDOM: How do you ad stylesheets to JSDOM So I've followed these instructions, and pulled in a rickshaw.css. When I print the DOM to console, I can see it in the head, in a style element. var