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
23
votes
2 answers

How to setup jsdom when working with jest

I'm trying to migrate from AVA to Jest. In AVA you can set ava.setup, in which you set the jsdom environment. For example, creating the DOM structure and doing necessary polyfills (localStorage). How do I accomplish that in Jest? Currently, I'm…
Gal Ziv
  • 6,890
  • 10
  • 32
  • 43
23
votes
5 answers

Unmount / destroy Component in jsdom test

Is there a way to unmount and garbage collect a React Component that was mounted using TestUtils.renderIntoDocument inside a jsdom test? I'm trying to test something that happens on componentWillUnmount and TestUtils.renderIntoDocument doesn't…
treznik
  • 7,955
  • 13
  • 47
  • 59
21
votes
4 answers

Calling setState in jsdom-based tests causing "Cannot render markup in a worker thread" error

I'm testing my React components under jsdom using my own tiny "virtual browser" utility. Works just fine, until I'm trying to setState. For example, when testing a children ages input control: describe('rendering according to the draft value',…
Ivan Krechetov
  • 18,802
  • 8
  • 49
  • 60
20
votes
5 answers

The current testing environment is not configured to support act(...) - @testing-library/react

I'm trying to upgrade my project to React 18, everything works in dev and production mode in the browser. But after upgrading to the latest version of @testing-library/react some of my unit tests are failing and a lot of them are logging the…
MLyck
  • 4,959
  • 13
  • 43
  • 74
20
votes
3 answers

Load a web page into a headless Jasmine spec running PhantomJS

How do I read in a page from localhost into a headless Jasmine spec so test cases can work on the DOM elements? My Gulp task is successfully running Jasmine specs for unit testing, and now I need to build integration tests to verify full web pages…
Dem Pilafian
  • 5,625
  • 6
  • 39
  • 67
18
votes
4 answers

How to test a component with a nested container with React and Redux?

Due to the complexity of the application I am working on I have decided on using a nested redux container rather than passing an action as a prop down to the child components. However, this has proved to be problematic for unit testing when…
Jon Yardley
  • 183
  • 1
  • 5
18
votes
5 answers

jsdom and node.js leaking memory

I found a few reference to people having a similar issue where the answer always was, make sure you call window.close() when done. However that does not seem to be working for me (node 0.8.14 and jsdom 0.3.1) A simple repro var util =…
Peter
  • 788
  • 7
  • 17
17
votes
2 answers

'globalThis' underfined for Jest test cases

I am using globalThis property specifically globalThis.scrollTo(0,0) in my React WebApp. I am using Jest for unit testing alongwith Enzyme. As of test cases fail as it is unable to identify globalThis and says that 'globalThis' is undefined. Is…
INDER
  • 343
  • 1
  • 4
  • 15
16
votes
6 answers

How do I test code that uses `requestAnimationFrame` in jest?

I want to write a jest unit test for a module that uses requestAnimationFrame and cancelAnimationFrame. I tried overriding window.requestAnimationFrame with my own mock (as suggested in this answer), but the module keeps on using the implementation…
htho
  • 1,549
  • 1
  • 12
  • 33
15
votes
7 answers

Building contextify under Windows 7 x64 (for NodeJS jQuery)

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,…
ngryman
  • 7,112
  • 2
  • 26
  • 23
14
votes
2 answers

jsdom window caching

Using jsdom.jsdom() in express.js I create a document with some 'base' layout markup and attach a few client side libraries such as jQuery to its window. It would be nice to only have to do this setup once. The problem is that the DOM of the…
cjroebuck
  • 2,273
  • 4
  • 30
  • 46
14
votes
1 answer

How to define container size for react-testing-library?

I have looked into similar questions (like this one), but the proposed solutions didn't work for me when using react-testing-library. I have a component that can receive multiple children. This component will then calculate its own size and its…
Bruno Monteiro
  • 4,153
  • 5
  • 29
  • 48
14
votes
1 answer

What is --env=jsdom

I was running my test suite for my react-native application with the command jest. The tests would fail in the file jest-runtime/build/index.js on the line const wrapper = this._environment.runScript(transformedFile.script)[ (_script_transformer ||…
bsky
  • 19,326
  • 49
  • 155
  • 270
14
votes
3 answers

jsdom: dispatchEvent/addEventListener doesn't seem to work

Summary: I am attempting to test a React component that listens to native DOM events in its componentWillMount. I'm finding that jsdom (@8.4.0) doesn't work as expected when it comes to dispatching events and adding event listeners. The simplest bit…
Jesse Buchanan
  • 1,099
  • 1
  • 9
  • 24
14
votes
2 answers

Edit elements in the jsdom window and save the window as a new HTML file?

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 am using is the…
Eva
  • 313
  • 1
  • 6
  • 17
1
2
3
54 55