Skip to content

Commit

Permalink
fix: detect RegExp from other contexts (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehb committed Sep 8, 2021
1 parent 2a1f1e6 commit 860106b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/index.ts
Expand Up @@ -31,7 +31,8 @@ function convertProxyToRegExp(o: any, depth: number): any {

function convertRegExpToProxy(o: any, depth: number): any {
if (typeof o !== 'object' || !o || depth > 2) return o
if (!(o instanceof RegExp)) {
// Support the cross-environment use case where `instanceof` is not sufficient, see https://github.com/testing-library/pptr-testing-library/pull/64
if (Object.prototype.toString.call(o) !== '[object RegExp]') {
const copy = {...o}
for (const key of Object.keys(copy)) {
copy[key] = convertRegExpToProxy(copy[key], depth + 1)
Expand Down

0 comments on commit 860106b

Please sign in to comment.