Skip to content

Commit

Permalink
chore: [#1510] Fixes failing integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
capricorn86 committed Aug 28, 2024
1 parent aaefaf2 commit 4a19851
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
1 change: 0 additions & 1 deletion packages/global-registrator/src/GlobalRegistrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export default class GlobalRegistrator {
}

// Set owner window on document to global
global.document[PropertySymbol.window] = global;
global.document[PropertySymbol.defaultView] = global;
}

Expand Down
11 changes: 11 additions & 0 deletions packages/global-registrator/test/react/React.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ async function main(): Promise<void> {

testGetters();

/**
* Test if Window properties are available on the global object.
*/
function testWindowProperties(): void {
if (!(globalThis.customElements instanceof globalThis.CustomElementRegistry)) {
throw Error('Expected globalThis.customElements to be an instance of CustomElementRegistry.');
}
}

testWindowProperties();

/**
* Test if it is possible to create a React component and mount it.
*/
Expand Down
11 changes: 5 additions & 6 deletions packages/happy-dom/src/window/BrowserWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,12 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
public readonly Element = Element;
public readonly CharacterData = CharacterData;
public readonly DocumentType = DocumentType;
public readonly Document = Document;
public readonly HTMLDocument = HTMLDocument;
public readonly XMLDocument = XMLDocument;
public readonly SVGDocument = SVGDocument;

// Nodes that can be created using "new" keyword (populated by WindowClassExtender)
public declare readonly Document: typeof Document;
public declare readonly HTMLDocument: typeof HTMLDocument;
public declare readonly XMLDocument: typeof XMLDocument;
public declare readonly SVGDocument: typeof SVGDocument;
public declare readonly DocumentFragment: typeof DocumentFragment;
public declare readonly Text: typeof Text;
public declare readonly Comment: typeof Comment;
Expand Down Expand Up @@ -505,7 +505,7 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal

// Public properties.
public readonly document: Document;
public readonly customElements: CustomElementRegistry;
public readonly customElements: CustomElementRegistry = new CustomElementRegistry(this);
public readonly window: BrowserWindow = this;
public readonly globalThis: BrowserWindow = this;
public readonly performance: typeof performance = performance;
Expand Down Expand Up @@ -619,7 +619,6 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal

this.#browserFrame = browserFrame;

this.customElements = new CustomElementRegistry(this);
this.console = browserFrame.page.console;

this[PropertySymbol.navigator] = new Navigator(this);
Expand Down
6 changes: 0 additions & 6 deletions packages/happy-dom/src/window/WindowClassExtender.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import BrowserWindow from './BrowserWindow.js';
import * as PropertySymbol from '../PropertySymbol.js';

import ElementImplementation from '../nodes/element/Element.js';
import DocumentImplementation from '../nodes/document/Document.js';
import HTMLDocumentImplementation from '../nodes/html-document/HTMLDocument.js';
import XMLDocumentImplementation from '../nodes/xml-document/XMLDocument.js';
Expand Down Expand Up @@ -64,11 +63,6 @@ export default class WindowClassExtender {
public static extendClass(window: BrowserWindow): void {
/* eslint-disable jsdoc/require-jsdoc */

// Element
class Element extends ElementImplementation {}
Element.prototype[PropertySymbol.window] = window;
(<typeof Element>window.Element) = Element;

// Document
class Document extends DocumentImplementation {}
Document.prototype[PropertySymbol.window] = window;
Expand Down

0 comments on commit 4a19851

Please sign in to comment.