Skip to content

Commit 40e64b0

Browse files
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.
1 parent 1917acc commit 40e64b0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ async function injectDOMTestingLibrary(container: ElementBase) {
4545
})
4646

4747
if (shouldInject.domTestingLibrary) {
48-
await container.execute(DOM_TESTING_LIBRARY_UMD)
48+
await container.execute(function (library) {
49+
// add DOM Testing Library to page as a script tag to support Firefox
50+
if (navigator.userAgent.indexOf('Firefox') !== -1) {
51+
const script = document.createElement('script')
52+
script.innerHTML = library
53+
return document.head.append(script)
54+
}
55+
56+
// eval library on other browsers
57+
return eval(library)
58+
}, DOM_TESTING_LIBRARY_UMD)
4959
}
5060

5161
if (shouldInject.simmer) {

0 commit comments

Comments
 (0)