Skip to content

Commit 860106b

Browse files
authored
fix: detect RegExp from other contexts (#64)
1 parent 2a1f1e6 commit 860106b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ function convertProxyToRegExp(o: any, depth: number): any {
3131

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

0 commit comments

Comments
 (0)