jsdom

error 'document' is not defined : eslint / React

心已入冬 提交于 2019-12-04 09:55:54
问题 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

I want to run d3 from a Cakefile

半城伤御伤魂 提交于 2019-12-04 09:39:01
问题 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

Loading ajax app with jsdom

风流意气都作罢 提交于 2019-12-04 09:22:19
I'm looking for a solution to bootstrap a client side app (written in Backbone.js) on the server, so that I can serve correct content to crawlers and non-js consumers. I've been playing around with jsdom & nodejs in an attempt to bootstrap the app, and can get it as far as loading in the basic template content, but the app appears to never start. I've tried 2 different solutions to make sure that I have all the dependencies necessary and the app is loading correctly: I tried using jsdom.env() with all the scripts usually included inline. I tried using jsdom.jsdom() and making sure that

mocha + jsdom + React TypeError: Cannot read property 'addEventListener' of undefined

六月ゝ 毕业季﹏ 提交于 2019-12-04 08:37:05
问题 I'm just getting started unit testing a React 0.10.0 component with mocha 2.3.3, jsdom 6.5.1, and Node.js 4.1.1. I have this for my unit test: var React = require('react/addons'); var TestUtils = React.addons.TestUtils; var sinon = require('sinon'); var expect = require('chai').expect; var jsdom = require('jsdom'); var view = require('../student-name-view.js'); describe('The student name view', function() { var renderedComponent = null; var nameChangedStub = sinon.stub(); var

Get DOM element's actual width using jsdom

纵然是瞬间 提交于 2019-12-04 04:24:11
I wonder if I could get a DOM element's actual width and coordinates, as I can get using .clientWidth / .offsetWidth from within the browser. Does jsdom has browser rendering capabilities in order to get this data? If not, how can I get this within node.js server? Thanks! JSDOM is strictly a DOM API emulation library. It does not attempt to actually render a document, which is necessary to compute element size and position. You may want to look at PhantomJS . It is a full WebKit renderer with a JavaScript API. It is entirely separate from node, so you either need to write a utility script

jquery doesn't work with jsdom/enzyme

馋奶兔 提交于 2019-12-04 03:21:31
问题 I have a minimum test react app with following component: import React from 'react'; import $ from 'jquery'; export default class App extends React.Component { componentDidMount() { console.log('componentDidMount', $('#helloDiv').length); } render() { return <div id='helloDiv'> Hello React! </div>; } } this works fine when loading it in browser (Chrome). The console.log() in componentDidMount() prints out 1 helloDiv element found However, if I run the test using mocha + enzyme + jsdom, the

How to add <canvas> support to my tests in Jest?

早过忘川 提交于 2019-12-03 23:32:04
问题 In my Jest unit test I am rendering a component with a ColorPicker. The ColorPicker component creates a canvas object and 2d context but returns 'undefined' which throws an error "Cannot set property 'fillStyle' of undefined" if (typeof document == 'undefined') return null; // Dont Render On Server var canvas = document.createElement('canvas'); canvas.width = canvas.height = size * 2; var ctx = canvas.getContext('2d'); // returns 'undefined' ctx.fillStyle = c1; // "Cannot set property

How do I return a value from a simple jsdom function?

不想你离开。 提交于 2019-12-03 15:41:21
I'm using jsdom with jquery, and it's working just fine. However, I'm trying to modularize my code a bit so I don't repeat myself, so I made a basic function out of some jsdom code that takes in some html (DOM), tweaks it with jquery, and spits it back out. However, I'm unable to return my result and thus assign it to a calling var. I'm probably not returning in the right place, but I'm just not seeing the obvious if so. Could use a little help. Here's the code: function tweakIt(html_in){ var jsdom = require('jsdom'); jsdom.env({ html: html_in, scripts: [ '../public/javascripts/jquery-1.7.1

How to fix “$ is not defined” error when unit testing Jquery with Typescript using Mocha?

拈花ヽ惹草 提交于 2019-12-03 14:15:49
问题 I am writing Mocha unit tests for Typescript code containing Jquery . I'm using jsdom for getting the document object. When I compile my TS code to JS and run the tests, it throws an error [ReferenceError: $ is not defined] . My Typescript code is here export function hello(element) : void { $(element).toggleClass('abc'); }; My unit test code is as follows: import {hello} from '../src/dummy'; var expect = require('chai').expect; var jsdom = require('jsdom'); var document = jsdom.jsdom(); var

Server-Side HighStock charts generation with NodeJS

天大地大妈咪最大 提交于 2019-12-03 14:04:36
问题 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,