From 29ea2899f48ecfd4b6bf17f15980f08ccc8af447 Mon Sep 17 00:00:00 2001 From: georgehb <32330689+georgehb@users.noreply.github.com> Date: Wed, 8 Sep 2021 16:14:23 +0100 Subject: [PATCH 1/3] Replaced instanceof RegExp This caused a problem in jest which runs each test in a separate execution context Fixes #63 --- lib/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.ts b/lib/index.ts index 9d9ba69..812d804 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -31,7 +31,7 @@ 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)) { + 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) From 9a205eaee1826b6707c137dacd19d9a908c68d16 Mon Sep 17 00:00:00 2001 From: georgehb <32330689+georgehb@users.noreply.github.com> Date: Wed, 8 Sep 2021 19:46:06 +0100 Subject: [PATCH 2/3] Update lib/index.ts Co-authored-by: Patrick Hulce --- lib/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.ts b/lib/index.ts index 812d804..0a526e9 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -31,7 +31,7 @@ function convertProxyToRegExp(o: any, depth: number): any { function convertRegExpToProxy(o: any, depth: number): any { if (typeof o !== 'object' || !o || depth > 2) return o - if (Object.prototype.toString.call(o) !== "[object RegExp]") { + 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) From 76ecb9f4356818e2ffe2fcfe82bd2a84d41e7616 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Wed, 8 Sep 2021 14:05:08 -0500 Subject: [PATCH 3/3] Update lib/index.ts --- lib/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/index.ts b/lib/index.ts index 0a526e9..0e905c7 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -31,6 +31,7 @@ function convertProxyToRegExp(o: any, depth: number): any { function convertRegExpToProxy(o: any, depth: number): any { if (typeof o !== 'object' || !o || depth > 2) return o + // 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)) {