Skip to content

Commit ec87bae

Browse files
fix: using Regular Expressions on Firefox
DOM Testing Library uses instanceof to check whether a query is passed a RegExp, a Function or a string arg. For some reason on Firefox when a RegExp is passed to a query the `arg instanceof RegExp` check is always false, resulting in RegExp arguments being treated like a string. It appears that this is because the RegExp that is created in executeQuery is not the same class as that used in the instanceof check in DTL. I'm not sure exactly what could be causing it, it's possible that this is due to a polyfill or how we are adding DTL to the page, or something completely different. Assigning the RegExp that is in scope in executeQuery to window.RegExp seems to fix the problem, presumably because it overrides whatever modified RegExp class was added by the UMD script.
1 parent 40e64b0 commit ec87bae

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ function executeQuery(
119119
;(async () => {
120120
let result: undefined | null | HTMLElement | HTMLElement[]
121121
try {
122+
// Override RegExp to fix 'matcher instanceof RegExp' check on Firefox
123+
window.RegExp = RegExp
124+
122125
result = await window.TestingLibraryDom[query](
123126
container,
124127
matcher,

0 commit comments

Comments
 (0)