From 40e64b0173cb61d7cb574ade88d34b450e986f9f Mon Sep 17 00:00:00 2001 From: olivierwilkinson Date: Tue, 15 Jun 2021 18:38:39 +0100 Subject: [PATCH] fix: injecting DOM Testing Library on Firefox Evaluating the UMD script is not enough to add TestingLibraryDom to the window when running on Firefox. Add a script tag to the head element with the UMD inlined to add TestingLibraryDom to the window. Why it doesn't work is not clear to me right now so there may be a better way of fixing this. I'm assuming this is a security feature of Firefox but that is a guess. --- src/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index e6c6160..1631299 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,7 +45,17 @@ async function injectDOMTestingLibrary(container: ElementBase) { }) if (shouldInject.domTestingLibrary) { - await container.execute(DOM_TESTING_LIBRARY_UMD) + await container.execute(function (library) { + // add DOM Testing Library to page as a script tag to support Firefox + if (navigator.userAgent.indexOf('Firefox') !== -1) { + const script = document.createElement('script') + script.innerHTML = library + return document.head.append(script) + } + + // eval library on other browsers + return eval(library) + }, DOM_TESTING_LIBRARY_UMD) } if (shouldInject.simmer) {