Questions tagged [jsdom]

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

Filter by
Sorted by
Tagged with
0 votes
0 answers
21 views

JSDom does not render XHR requests

I'm trying to make JSDOM behave like a browser and return rendered html. I'm having a problem with a website that uses XHR. Is there any incompatibility? JSDOM doesn't work with XHR?? I tried several ...
Bruno Andrade's user avatar
0 votes
1 answer
28 views

How can I get the textContent of an element?

I was trying to extract a text from a website, I found a lot of tutorials but none of them could give me insights to solve the problem. The code below is returning me no text, it does print but its ...
constperson's user avatar
0 votes
0 answers
22 views

Having issues using puppeteer and jsdom to parse the HTML of a website

I am currently trying to create a javascript program that will parse the HTML from a webpage and then take each HTML tag put it into array so I can further select it for processing. I am using ...
ecurtis28's user avatar
3 votes
1 answer
51 views
+100

Vitest and unimport with axios, pusher and/or Echo on window object

I'm using vitest and @vue/test-utils to test a Laravel/Vue3 UI. The boostrap.js file adds axios, pusher and Echo to the window object and the components then have access to use them directly without ...
Matt Larsuma's user avatar
  • 1,388
-5 votes
0 answers
50 views

Count number of elements/tags at top level of a given string of HTML/XML in Node.js [closed]

I'm trying to write a function in JavaScript, that can correctly identify how many top level elements exist in a given string of HTML/XML (in this case it's a Vue JS Template). I need to do this in ...
Cade Embery's user avatar
0 votes
2 answers
49 views

How can I determine the type of an HTML element in Jest?

I need a way to determine the type of an HTML element in Jest. I have tried below code to see If HTMLLabelElement is available. I am getting ReferenceError: HTMLLabelElement is not defined Jest it() ...
Priya's user avatar
  • 66
0 votes
1 answer
96 views

onChange is not called when used with userEvent.type from React testing library

I am using RTL with Jest to test a Slate editor. I use .type to emulate a user typing into the editor and expect that Slate's onChange will be called. However, this does not happen. Here's my editor ...
George Eracleous's user avatar
0 votes
1 answer
51 views

How do I fix Chrome Extension "Uncaught Reference Error: document is not defined" error? [duplicate]

I'm creating an extension, and I want it to be able to find specific words on any website and highlight them. However, after I loaded my extension, I promptly got an error message. Does anyone know ...
thelovelightliveventure's user avatar
0 votes
0 answers
19 views

What do you use for unit testing KendoReact components?

I'm trying to encourage frontend unit testing and have been having a great time with testing-library/react. We just got a KendoReact license for the Editor component. I'm trying to just render it in a ...
Chris's user avatar
  • 3
0 votes
0 answers
64 views

Nextjs 13 able to fetch and scrape a webpage when running the server locally, but when the application is deployed on Vercel, the fetching fails

Here's the GET function that is scraping the website export async function GET(req) { const itemNumber = req.url.split("scrape_costco/")[1]; console.log("Item #: ", itemNumber);...
Martin Vera's user avatar
-1 votes
1 answer
66 views

How to mock document.documentElement in a Jest test case?

I have a function that simply returns the 'lang' attribute from the document.documentElement as: const getLang = () => document.documentElement.getAttribute('lang'); I need to write a test case ...
Rutwick Gangurde's user avatar
0 votes
0 answers
25 views

Overriding `Function.prototype.toString` in JSDOM for a specific function

I'm using JSDOM and trying to mock the behavior of window.Function.prototype.toString.call(window.WebGLRenderingContext.prototype.getParameter). I want it to return 'function getParameter() { [native ...
Jay's user avatar
  • 1
0 votes
0 answers
50 views

Using jsdom with Readability in the context of Expo

I'm new to Expo and React Native and I am trying to use @mozilla/readability package in an app, to clean up a web page. As far as i can tell, since I'm not running the readability code in the browser ...
mircealungu's user avatar
  • 6,831
1 vote
0 answers
14 views

AVA test with JSDOM: Cannot set property window of #<Object> which has only a getter

I want to test in AVA a method that use global "document", eg. export const blurActiveElement = (): void => { if (typeof window.focus === 'function') { window.focus(); } ...
ar099968's user avatar
  • 6,967
0 votes
2 answers
79 views

change text in button with javascript vanilla

I know that my question it may seem very simple. But i can´t change my text button. My button in web browser console it´s: <button class="nav-link active" id="coholder-tab" data-...
scorpions77's user avatar
0 votes
1 answer
23 views

NodeJS framework for manipulating a virtual DOM and syncing changes to a browser

I am developing a nodejs application and I am interested in manipulating a virtual representation of the DOM on the server side and then syncing these changes to a connected browser in real time. I ...
umop's user avatar
  • 2,132
-3 votes
2 answers
59 views

Is there an easier way to call JS functions in Node.js via HTML-buttons?

I'm trying to add a JavaScript function that I wrote myself, to an HTML button which I also did myself. I'm having problems calling the document.getElementById() function because I'm working with Node....
ElEss's user avatar
  • 3
1 vote
0 answers
42 views

importing issue for jsdom package for jest testing framework

I am getting TextEncoder error message when testing a div created by jsdom package using Jest framework. I am having below node.js and jsdom version : Node.js version: v16.17.0 jsdom version: v22.1.0 ...
Shraddha Kurud's user avatar
0 votes
1 answer
386 views

How to get the lexical editor state, programmatically, from the parsed html string?

My use case is to upload the Excel sheet, in the React UI, with multiple rows in it. Each row is corresponding to a question. The different question fields will be having HTML strings in them. After ...
Yaju's user avatar
  • 1
0 votes
0 answers
137 views

Unit testing JavaScript meant for the browser with Jest and JSDOM

I'm trying to create unit tests for JavaScript that modifies the DOM in a page. For example: function setBodyTo(str) { document.body.innerHTML = str; } <html> <head> &...
rafa's user avatar
  • 336
0 votes
0 answers
51 views

React Select fires blur event when selecting an option in test (jsdom environment)

A simple React Select control with only options and a blur handler works perfectly inside my application (i.e. in the browser) but the blur handler is called when I select an option within an ...
lex82's user avatar
  • 11.2k
1 vote
0 answers
449 views

jest test in react 18 failing because unable to find testid in react-dom, using createRoot

Using react 18 and looking to write jest tests with version 29.5.0. I'm getting this error when running my jest test TestingLibraryElementError: Unable to find an element by: [data-testid="/...
user3226932's user avatar
  • 2,062
0 votes
0 answers
33 views

Accessing browser objects within a module using JSDom

Context: Using JSDom, I am trying to create a helper to define unit tests for frontend side in a simple and straightforward way. The helper lets to define an HTML context and then add a function to be ...
Javier Vélez's user avatar
0 votes
1 answer
22 views

Using jtest how to pass a mock dom to the function being tested

I am new at jtest; I want to be able to unit test a function (that normally runs in a browser). Here's a simple situation where I thought the document was passed to the test function but it is not. ...
ArchipelagoT's user avatar
0 votes
0 answers
282 views

focus-trap-react error when testing with vitest and jsdom

I am having the following error when trying to test components with vitest running js-dom environment that use focus-trap-react . Error: Your focus-trap must have at least one container with at least ...
Dimitar Nizamov's user avatar
1 vote
1 answer
36 views

How to get image details within an anchor element <a><img src></a>

I am using nodejs and jsdom, attempting to retrieve images used within anchor tags. I can enumerate the images using .querySelectorAll("img"); and the anchors using .querySelectorAll("...
William Vincent's user avatar
0 votes
0 answers
27 views

Angular 15 SSR - Component 'f' is not resolved: - templateUrl: ../../templates/header/header.component.html

I am trying to implement Angular Universal to an Angular 15 application that uses window and jquery. I have added the JSDOM package to use window object in server.ts and also added webpack.server....
Charanjeet Singh's user avatar
0 votes
0 answers
27 views

Error: unable to verify the first certificate

I'm using the jsdom library to scrape data from a website Weather Related but this website does not have a complete certificate chain. So I get the following error. const { JSDOM } = require('jsdom'); ...
Ukhu's user avatar
  • 19
0 votes
0 answers
103 views

MutationObserver in JSDOM fails because parameter 1 is not of type Node

I am trying to test a simple JavaScript single page application using JSDOM and Jest. For our purposes here, index.html is a simple html document that contains the tag <div id="app-root"&...
James Frank's user avatar
5 votes
2 answers
2k views

ws does not work in the browser. Browser clients must use the native WebSocket object

Node JS application giving a websocket error in a JEST, Puppeteer test. Chromium opens for a second and then closes instantly. I am not using websocket in my test so not sure why the attached error is ...
NoName's user avatar
  • 91
0 votes
1 answer
227 views

Mock audio player events with Jest

I'm trying to test my own audio player (based in an html audio element) however I've been unable to mock the emission of events (onended, onerror, etc). Is there a way of mocking these events using ...
Mauricio Ruiz's user avatar
0 votes
0 answers
179 views

How to test Material UI drawer with custom styles?

I'm trying to test a Material UI drawer component in my React app with custom styles, but I'm having trouble getting the left position to apply. In the browser Dev tools, I see that the left position (...
Lori's user avatar
  • 182
6 votes
0 answers
2k views

Vitest config doesn't detect jsdom environment

I'm in a Vite/React/TypeScript application and I'm configuring my first test with Vitest. When I run my Button test (yarn vitest), I get this error: packages/frontend/src/components/Generic/Button/...
tomakazub's user avatar
  • 237
0 votes
1 answer
137 views

Unit testing monaco editor renders only first line

I am using vite+vitest for my project. I installed vitest-canvas-mock and its successful in running the tests. But it is rendering only the first line in the code. I am not able to add text or see any ...
Vamshi's user avatar
  • 9,204
1 vote
0 answers
144 views

TypeError: Expected input type is Uint8Array (got object)

I am trying to make a frontend application in which I'm using jest for testing the frontend layers. For the same, I want to get the provider from the HDWalletProviderFactory here but when I try to do ...
newbie's user avatar
  • 41
1 vote
1 answer
360 views

Memory leak when using 'node-fetch' and 'jsdom'

I'm trying to solve a memory leak when running the below code, called runeveryminute.js, once a minute. Every time, I'm seeing a ~5MB increase in data usage that isn't getting garbage collected. When ...
garson's user avatar
  • 1,515
0 votes
0 answers
95 views

how to write test code for pdfjs using mocha

While using mocha and chai to test my pdfloader (which uses pdfjs) it does not enter the getDocument() function. pdfjsLib.getDocument( 'http://localhost:8080/document.pdf', window.document, ...
ousmorez's user avatar
1 vote
1 answer
741 views

JSDOM NextJS error on launch: Module not found: Can't resolve 'net' [duplicate]

Need Help I was building my first big NextJS project with News API and wanted to use jsdom to scrape the news URL, but when I import this dependency into my project I get the Module not found: Can't ...
Yagi91's user avatar
  • 35
0 votes
0 answers
77 views

How to fix Cannot find module './xhr-sync-worker.js' in AWS lambda

I have a lambda function that does a bit of server side rendering. I am using lambda's esbuild config. Here is a look at the config. I guess its similar to this issue but different since I am not ...
00robinette's user avatar
0 votes
1 answer
86 views

Inconsistent behaviour of mocking DOMPoint in Jest

I have a number of geometry functions that use DOMPoint and DOMRect, which I want to test using jest. The framework is configured to use jsdom as test environment. Unfortunately, jsdom does not have ...
Mike Lischke's user avatar
  • 49.2k
0 votes
2 answers
484 views

'Unsuported type :hover' and 'Unknown pseudo-class selector :visible'

I'm not able to use selectors with pseudo classes in a jsdom test environment. Is there any trick to do this or some mandatory configuration? For example, if I do $("button:hover") I get the ...
Ninita's user avatar
  • 1,209
1 vote
0 answers
375 views

The Testing Library's fireEvent.click() not working on my Vanilla JS app

Am trying to test if a <p class="output"> element value is incremented after clicking the element. The app app works fine when I run it in the browser and click the button because the ...
Stanley Ulili's user avatar
1 vote
1 answer
147 views

Why am I getting TypeError jsdom.createVirtualConsole() is not a function

I'm doing some prework for a bootcamp. I have an environment set up using WSL, ubuntu, node.js, python and ruby. when I run npm list jsdom I get jsdom 20.0.3. I'm trying to run a test in VS using ...
Giselle Smith's user avatar
3 votes
3 answers
3k views

Vitest with React Testing Library 'Unexpected Token'

I'm using react with ViteJS and Vitest for testing. I have set up the config for vitest and the test setup file too as you can see in the screenshots below. vite.config.js src/test/setup.ts src/app/...
SaboSuke's user avatar
  • 644
0 votes
0 answers
85 views

Jest Test suite failed to run Cannot find module after update to 29.xxx

This is my config : module.exports = { globalSetup: '<rootDir>/config/jest/setupEnv.js', setupFiles: ['<rootDir>/jest.setup.js'], transform: { '^.+\\.(js|jsx|ts|tsx)$': ['babel-...
Fiqry choerudin's user avatar
0 votes
1 answer
111 views

How to build an HTML DOM from a multiline string and access child elements in Jest?

Problem: I'm trying to build an HTML DOM from a multiline string in Jest in order to test a browser extension. However, when I try to access the child elements of the DOM, they are being returned as ...
baruchiro's user avatar
  • 5,118
0 votes
0 answers
128 views

How to find out which package version has the required nested version?

I need to install jsdom@19 because it has a bugfix that I need, and I don't have it installed directly in package.json, it's a nested dependency. To find out which dependency is installing it I ran ...
Kareem Kamal's user avatar
  • 1,028
2 votes
0 answers
554 views

Can't use Jest to test responsive design using Tailwind CSS

I'm using TailwindCSS to implement a React App, and Jest to test it. I expect changing the window size can cause some elements to appear and disappear. Then I realized jsDom doesn't load TailwindCSS, ...
Hao's user avatar
  • 65
0 votes
0 answers
149 views

JEST late test case affects previous test case

I'm writing a unit test to check if a certain section would appear if a related button is clicked An I have this piece of code const sections = [...document.querySelectorAll("section")]; ...
Louay Hamada's user avatar
0 votes
0 answers
82 views

How to add window.URL.createObjectURL to jsdom

I have an application without DOM. So, I have added jsdom library to it but it doesn't have window.URL.createObjectURL function and gives undefined error. Is there a way to add this function to this ...
Manik Malhotra's user avatar

1
2 3 4 5
17