Skip to content

"TypeError: Cannot redefine property: window" (v18.6.0) #47563

Closed as not planned
@vodzak

Description

@vodzak

Version

v18.16.0

Platform

21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64 x86_64

Subsystem

No response

What steps will reproduce the bug?

const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
global.window = jsdom.window as any;

How often does it reproduce? Is there a required condition?

Error is consistent. This error did not occur when using Node 18.15.0, and also does not occur when using Node 19.9.0.

What is the expected behavior? Why is that the expected behavior?

Expected behavior is no error.

What do you see instead?

TypeError: Cannot redefine property: window

Additional information

Same issue as: #47310

Similar to that issue, I've run into this error when running tests that use JSDom:

  1. Save the following as "test.js":
/**
 * @jest-environment jsdom
 */

"use strict"
global.window = {};

describe("test", () => {
    it("runs", () => {
        expect(1 + 1).toEqual(2);
    });
});
  1. Run npm i jest jest-environment-jsdom
  2. Run npx jest

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions