Skip to content

Commit

Permalink
fix: do not execute <PrismicToolbar>'s script during happy-dom tests
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed May 25, 2022
1 parent add20dd commit 72aaa1e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/PrismicToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ export const PrismicToolbar = ({
script.dataset.repositoryName = repositoryName;
script.dataset.type = type;

// Disable happy-dom `<script>` evaluation during tests.
//
// This is a patch ONLY INCLUDED DURING TESTS. It will
// be pruned during code minification in non-test
// environments.
//
// @see https://github.com/capricorn86/happy-dom/blob/02ae081e36f990c06171eda44f9d885fd9413d73/packages/happy-dom/src/nodes/html-script-element/HTMLScriptElement.ts#L191-L209
if (process.env.NODE_ENV === "test") {
// @ts-expect-error - `_evaluateScript` is a happy-dom-specific property.
script._evaluateScript = false;
}

document.body.appendChild(script);
}
}, [repositoryName, type, src]);
Expand Down

0 comments on commit 72aaa1e

Please sign in to comment.