Questions tagged [jsdom]

Implementation of the WHATWG DOM and HTML Standards (among others) for node.js

jsdom allows construction of in-memory and in-process objects that represent the window, document, etc. from a browser. It tries to implement the latest DOM and HTML standards, among many others like the CSSOM.

820 questions
14
votes
5 answers

Simulating click on document ReactJS/JSDom

So I am writing some tests for code that adds a click event on the document. I am using JSDom, ReactJS, and Mocha/Chai setup. I have tried the following code in a test: document.addEventListener('click', function() { …
ryanzec
  • 27,284
  • 38
  • 112
  • 169
14
votes
4 answers

D3js : How to convert svg text to path?

Is there a D3.js way to convert a text element into a path element? So when I grasp the generated svg, I could keep my the texts shapes.
Hugolpz
  • 17,296
  • 26
  • 100
  • 187
13
votes
1 answer

How to test Web Component (lit-element) with jest

Anyone has a good setup for testing custom elements with jest, jsdom or similar? I have been using Puppeteer and Selenium, but they slow down the test runs too much. Any other alternatives or fixes for jsdom that makes the below test…
tirithen
  • 3,219
  • 11
  • 41
  • 65
13
votes
4 answers

Testing a react-mapbox-gl with jsodom and jest

Consider we have the following Map component. This is in TypeScript, but the same should apply for normal JavaScript. import * as React from 'react'; import ReactMapboxGl from 'react-mapbox-gl'; const MapBox = ReactMapboxGl({ accessToken:…
Rovanion
  • 4,382
  • 3
  • 29
  • 49
13
votes
4 answers

How can I configure the jsdom instance used by jest?

I've come up against this issue Invalid URL is thrown when requiring systemjs in jest test cases One of the last comments suggests "manipulate the jsdom instance to have a valid location / baseURI by setting the referrer config in jsdom." I'm…
user5325596
  • 2,310
  • 4
  • 25
  • 42
13
votes
3 answers

How to use jQuery with jsdom@5?

I am migrating from node.js to io.js and my old node.js code does not work with jsdom@5. var jsdom=require('jsdom'); var $=require('jquery')(jsdom.jsdom().createWindow); Here is the error: /tmp/iojs/node_modules/jquery/dist/jquery.js:28 …
untitled
  • 1,037
  • 2
  • 12
  • 27
13
votes
2 answers

How do you add stylesheets to JSDOM

I am currently working on a project that requires me to have computed styles send to the browser via JSDOM. I am currently looking for a way to inject some basic CSS into JSDOM so that it could compute the correct inline style (Yes I know that's…
Paul
  • 276
  • 2
  • 10
12
votes
7 answers

npm install jsdom error on windows?

I have installed nodejs on my windows pc. And it was working fine. But when I tried to install jsdom using "npm install jsdom" I was prompoted by this error. node "C:\Program …
Jrubins
  • 249
  • 1
  • 4
  • 11
12
votes
2 answers

Installing jQuery gives webpack errors

I npm installed jQuery and am now seeing a bunch of Module not found: Error: Can't resolve... errors. Any idea of what the root issue could be and a resolution? ERROR in ./node_modules/jquery/lib/node-jquery.js Module not found: Error: Can't…
chewchew
  • 217
  • 3
  • 11
12
votes
5 answers

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

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…
Aditi
  • 123
  • 1
  • 1
  • 6
11
votes
2 answers

post a form using jsdom and node.js

I am using jsdom, jquery and node.js to scrape websites. Is there any way I can post a form and get the resulting next page window using jsdom. Here is the code var httpAgent = require('http-agent'), jsdom = require('jsdom'), request =…
Madhusudhan
  • 8,374
  • 12
  • 47
  • 68
11
votes
3 answers

JSDOM is not loading JavaScript included with