Skip to content

Commit

Permalink
fix: injecting DOM Testing Library on Firefox
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
olivierwilkinson committed Jun 15, 2021
1 parent 1917acc commit 40e64b0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 40e64b0

Please sign in to comment.