Skip to content

Commit

Permalink
Do not reset global.document before CustomElement:disconnectedCallbac…
Browse files Browse the repository at this point in the history
…k has finished running, document should be accesible in this callback function
  • Loading branch information
dalvarezmartinez1 committed Sep 13, 2021
1 parent d7f0975 commit c6d4dd1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/jest-environment-jsdom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,14 @@ class JSDOMEnvironment implements JestEnvironment<number> {
if (this.errorEventListener) {
this.global.removeEventListener('error', this.errorEventListener);
}
this.global.close();

// Dispose "document" to prevent "load" event from triggering.

// Note that this.global.close() will trigger the CustomElement::disconnectedCallback
// Do not reset the document before CustomElement disconnectedCallback function has finished running,
// document should be accesible within disconnectedCallback.
Object.defineProperty(this.global, 'document', {value: null});
this.global.close();
}
this.errorEventListener = null;
// @ts-expect-error
Expand Down

0 comments on commit c6d4dd1

Please sign in to comment.