Questions tagged [jsdom]
Implementation of the WHATWG DOM and HTML Standards (among others) for node.js
747
questions
0
votes
1
answer
27
views
React Router navigate away to new URL with tests
In my app I have react-router, redux and redux-first-history all working nicely. Certain routes in certain circumstances must navigate the user to another website e.g. for authentication with SAML. As ...
0
votes
0
answers
46
views
Does jsdom support function fetch when parsing string or loading urls in nested <script> tags?
Probably a very beginner question as I am a just learning. I'm using a windows 10 Nodejs latest distribution as well as a 512 Meg tiny core 32 virtual box distribution.
The ultimate goal is to read ...
0
votes
0
answers
12
views
How to pass document variable to ES6 Module during Jasmine testing
I want to test if a function in a module generated something in document but I am having trouble defining the document variable. I have simulated it jsdom but I am unable to define it in module.
In my ...
0
votes
0
answers
7
views
Event listener is not running if/else statement?
I believe my if/else statements are not running and end up not making the changes to the elements I target. When I run it, I believe the parent element is not being called correctly for the first ...
0
votes
0
answers
38
views
How can I add DOM support with JSDOM to use functions like document.getElementById() when using NodeJS [duplicate]
Ello!
I am looking to change apart of my inner html using document.getElementById("textToChange").innerHTML.
However, I keep getting this error when I attempt to run my JS file with node ...
6
votes
1
answer
642
views
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 ...
0
votes
0
answers
11
views
React with JSDOM has a constructor for e.target that is not HTMLFormElement?
So I'm getting this error while running my tests with babel-jest:
Error: Uncaught [TypeError: Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.]
at reportException (/[...
1
vote
1
answer
74
views
@testing-library waitfor not finding element in lazy loaded component
I'm trying to use @testing-library/react waitfor to wait for a lazy loaded component before I compare snapshots.
The App.tsx is simply this:
const MyComponent = lazy(() => import('my/component'));
...
0
votes
0
answers
24
views
How to get document.documentElement.getBoundingClientRect().height in node js?
I was try to get the height from html. I render the html using ejs because I need to insert a data into the html and then the result from ejs was processing with jsdom library.
I was write <script&...
-1
votes
0
answers
25
views
Getting css while scraping website even though I didn't call it
var html = await axios.get('https://reaperscans.com/all-series/comics/page/4/?m_orderby=manhwa');
var dom = new JSDOM(html.data);
var rip=dom.window.document.querySelectorAll(".h5")....
1
vote
1
answer
23
views
I am getting non breaking space as a text when scraping website span
I scrapeed a website and got essential text but it's also giving non breaking space with the text anyway I can remove those nbsp? Here is the generated output by console :-
Action / ...
0
votes
1
answer
110
views
ReferenceError: document is not defined when doing svelte tests
i get this error
FAIL src/components/Buttons/Create.test.js
✕ shows proper heading when rendered (1 ms)
● shows proper heading when rendered
The error below may be caused by using the wrong ...
0
votes
0
answers
40
views
Web scrapping using axios and jsdom isn't getting image src
const axios = require('axios');
const jsdom = require('jsdom');
const {JSDOM} = jsdom;
(async () => {
const html = await axios.get('https://mangadex.org/titles/latest');
const dom = new ...
0
votes
1
answer
75
views
Mocking JavaScript Math.random with Jest doesn't work
Math.random() always giving random values instead of mocked ones.
index.test.js
jest.spyOn(global.Math, "random").mockReturnValue(0.123456789);
const html = fs.readFileSync(path.resolve(...
2
votes
1
answer
73
views
Node.js Application, leveraging JSDOM and node-canvas, trying to drawImage from one canvas to another
I have a code snippet, where I'm leveraging two canvases...
One is generated in an emulated DOM, using JSDOM...
and the other is directly using NPM-Canvas
I am using heatmap.js to create an image in ...
0
votes
0
answers
48
views
Convert string read from a local mdx file to a window.document object
I have a next.js project using mdx-bundler'
Is there a way to convert string read from a local mdx file to a window.document object so I can use querySelector to query dom elements?
for example, I ...
0
votes
0
answers
35
views
How to load script that uses `window` object in jsdom (jest)
I am a beginner to jest, not sure how do I test a script that's suppossed to be run in the dom, if possible I don't want to load the dom, just app.env.js
app.env.js
window.APP_ENV = Object.freeze({
...
1
vote
0
answers
90
views
ReactJS testing causing a typeError: network request failed
I have been trying to simulate file-upload as a test for my react-app but that was generating the following error :
TypeError: Network request failed
at node_modules/whatwg-fetch/dist/fetch.umd.js:...
1
vote
0
answers
79
views
document object doesn't work properly in test with jest jsdom
I am using jest with jsdom to test my application.
/**
* @jest-environment jsdom
*/
const html = fs.readFileSync(
path.resolve(__dirname, "../public/index.html"),
"utf8"
);
...
0
votes
1
answer
42
views
Finding and replacing attribute in HTML File
I have a project folder which contain list of HTML file which contain some knockout syntax , I am looking some pointer where are I search for certain pattern of attribute and replace it will new ...
0
votes
1
answer
41
views
How to calc svg text element bounding box in nodejs server
FontSize is 60, but the bounding box shows that render height is 84px. How to use fontFamily or lineHeight or other way to calc it in nodejs server
0
votes
0
answers
22
views
JSdom and pseudoclasses
I'm using node and jsdom for some scraping. I have:
const fragments = await document.querySelectorAll("div[data-qa] a:has[span]");
This results in the message:
unknown pseudo-class selector ...
0
votes
0
answers
122
views
Test: Focussing an element doesn't trigger the CSS update based on the :focus pseudo class
What do I want to do?
Using the CSS pseudo class :focus to determine whether an element has the style display: block or none.
It works perfectly fine in the browser!
What is not working ?
I'm running ...
0
votes
0
answers
83
views
Jest - test html <details> tag with Error: Uncaught TypeError: Cannot read property 'body' of null
I have tried to test my simple detail react component with jest, jsdom, enzyme without success. If I want to set attribute "open" of my detail component to true, then the jest will run in to ...
0
votes
1
answer
35
views
Loading html into chrome followed by jsdom instance
I'm doing some scraping after receiving html from an api. I'd like to do the following:
Open html page in chrome so I can find selectors in the console.
Immediately load the same html page into a ...
0
votes
1
answer
35
views
How do I test an inner function that is been looped over with jest
How do you test an inner function that is been looped over in jest?
Example I have:
index.js
const innerFunc = (type) => document.querySelector(`input[name="${type}"]`).value;
const ...
0
votes
0
answers
50
views
How do you test a form upon the submission addEventListener with jest without a framework only vanilla JS
Most of the research I have done in regards to jest testing unit testing and/or integration testing is all heavily geared towards React. But I am not using react on this project, using vanilla ...
0
votes
0
answers
51
views
fireEvent.click() not working with mocha and jsdom
I have a simple test case that is failing to click the button. The button exists and is found, but firing the click event is not triggering the onClick handler for the button. Unsure if this is ...
0
votes
0
answers
460
views
ReferenceError: TextEncoder is not defined when importing jsdom library
I have these two files:
test.js:
const jsdom = require("jsdom");
const hello = () => {
console.log("hello!");
};
module.exports = {
hello
};
and
server.js:
const ...
0
votes
0
answers
32
views
Running a function (not from a <script> tag) in the context of JSDOM's window object
There are several descriptions of how to run html-embedded scripts with JSDOM, yet I would like to run a function declared in the normal node.js context with a global object from jsdom, like:
import { ...
0
votes
0
answers
60
views
Vue with jest & jsdom test, TypeError: svg.createSVGPoint is not a function
When I am testing my vue component that use d3js with jest, I got this error
[Vue warn]: Error in mounted hook: "TypeError: svg.createSVGPoint is not a function
I saw on the internet it is due ...
0
votes
1
answer
37
views
How to get full html source from jsdom
I am using JSDOM to modify html text using jquery. After I modify it with jquery, i need the full html. I tried the code below, but it wob't give <!Doctype html> and all. How to get the full ...
0
votes
1
answer
38
views
Change global var inside a JSDom document
I'm trying create a JSDom document that contains a global var and then trying to change it's value programatically and then print the output again.
My code is the following:
const { JSDOM } = ...
2
votes
0
answers
74
views
dynamic commonJS module loading with parcel
I have as part of my application
"use strict";
exports.makeNodeCompatible = function() {
if (typeof(DOMParser) === 'undefined') {
(function(global) {
var jsdom = require('jsdom')...
0
votes
1
answer
29
views
Keep DOM event handlers when writing an SVG to file
I'm creating an SVG using JSDOM and D3, and then writing it to an SVG file using FS in a Node environment. This SVG has event handlers attached to it for "drag" events, but these handlers ...
1
vote
1
answer
84
views
How to set up Visual Regression of react-chartjs-2 component
I am trying to set up visual regression testing for react-chartjs-2 components with React Testing library. However, all of the snapshots that are being generated are blank, but the component renders ...
0
votes
1
answer
46
views
I'm dealing with an issue in Axios (in my code). What do I do?
So, I was trying to create a simple web scraper to extract data from Wikipedia using Node.js, and I used Axios & JSDOM to do it.
When I tried to run it, this was the message I received on my ...
3
votes
1
answer
252
views
How to set global.TextDecoder in jest for jsdom if node's util.TextDecoder is type mismatch?
Try to use jsdom with Jest in an NX repo (typescript/angular) and I get the problem that TextEncoder and TextDecoder are not present. I get the same result whether I set the jest testEnvironment to '...
0
votes
2
answers
99
views
window.CCapture is not a constructor in Node.js
I'm trying to load CCapture in Node.js instead of having to run a headless browser to record canvas stream. I keep getting window.CCapture is not a constructor error.
CCapture Library Link - https://...
0
votes
0
answers
34
views
JSDOM.serialize() showing initial View Source, not full DOM (node.js)
I'm trying to load a page's full DOM using jsdom package for node.js. I have read the relevant documentation and a couple seemingly similar questions but I am still having a problem. Here's the node....
0
votes
1
answer
404
views
Using jsdom in chrome extension manifest v3
In chrome extensions manifest v3 it's stated that background.js is now replaced with service worker and dom is not available in a service worker. Then suggests undom or jsdom to be used as an ...
0
votes
0
answers
65
views
JointJS Draw SVG with NodeJS in backend Server
For an industrial project, we have to draw a large quantity ( ~400 / 500) of diagrams made with jointjs and export them as SVG in one PDF file.
For performance purposes, the drawing should be more ...
0
votes
2
answers
57
views
Is there a way in Echarts to show a series chart for a full day then plot the values onto it?
I'm building a pet project to help manage my diabetes. I'm totally new to echarts so if I could get some pointers I would much appreciate it.
What I'm asking is, is there a way to show a chart (per ...
1
vote
0
answers
47
views
Testing welcome paragraph to equal to "welcome" instead of empty string
I am using jest, jsdom and testing-libray/dom to test this page (index.html). i expect paragraph to be "welcome" but i am getting empty string ("") because a page (index.html) is ...
0
votes
0
answers
103
views
How to replace JSDOM with cheerio for Readability
I'd like to use Readability to parse out the "article" content within web pages. Readability does a good job, but it depends on JSDOM which seems to be very slow and throws errors if parsing ...
0
votes
0
answers
105
views
Unable to run karma+JSDom tests on NodeJS 17.x
Simple 'hello world' tests executes nicely with latest Karma+webpack+JSDom (+karma-jsdom-launcher) on nodejs 12, nodejs 14 and nodejs 16.
But on latest NodeJS 17 (tried both 17.0 and 17.2) i have an ...
0
votes
0
answers
36
views
React doesn't issue any error but html file still doesn't get the rendered html from react
So I was trying to send this rendered HTML to the staff-home.html. It seems like the path specified in JSDOM.fromFile is correct because I console logged the html div which would receive the react ...
1
vote
0
answers
624
views
How to use jsdom to manipulate DOM in chrome extension V3 from service worker(background script)?
I'm trying to manipulate an HTML string in the background script, that in the chrome extension V3 is using a service worker.
In the migration documentation it is mentions to use jsdom in order to get ...
0
votes
1
answer
132
views
How to scrape a webpage using JavaScript?
I have the following DOM parts that I want to scrape. At first there is a drop down list after and after an element is selected, a second drop down list is presented which if an element is selected ...
0
votes
2
answers
347
views
How to get XML Attributes with XPath in JSDOM
I can't seem to be able to get XML Attributes using JSDOM and XPath Syntax on this XML Snippet.
<PARAGRAPH>
This is a text, about something, that happened on
<DATE ISO="20131117&...