Skip to content

Commit

Permalink
fix: using Regular Expressions on Firefox
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
olivierwilkinson committed Jun 15, 2021
1 parent 40e64b0 commit ec87bae
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ function executeQuery(
;(async () => {
let result: undefined | null | HTMLElement | HTMLElement[]
try {
// Override RegExp to fix 'matcher instanceof RegExp' check on Firefox
window.RegExp = RegExp

result = await window.TestingLibraryDom[query](
container,
matcher,
Expand Down

0 comments on commit ec87bae

Please sign in to comment.