From 7d2996216c9eb91ea453cb4dc1f281514004c94d Mon Sep 17 00:00:00 2001 From: Seth Silesky <5115498+silesky@users.noreply.github.com> Date: Thu, 26 Jan 2023 10:10:41 -0600 Subject: [PATCH] Refactor .get test (#1000) --- .gitignore | 5 +- packages/core/src/__tests__/get.iso.test.ts | 52 +++++++++++++-------- packages/core/src/__tests__/get.test.ts | 44 ----------------- 3 files changed, 37 insertions(+), 64 deletions(-) delete mode 100644 packages/core/src/__tests__/get.test.ts diff --git a/.gitignore b/.gitignore index 72d63c61fd..35b316e330 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,7 @@ package-lock.json .env # JetBrains byproduct .idea -coverage \ No newline at end of file +coverage + +# playwright +playwright-report diff --git a/packages/core/src/__tests__/get.iso.test.ts b/packages/core/src/__tests__/get.iso.test.ts index f8dd066ef5..40dce14f54 100644 --- a/packages/core/src/__tests__/get.iso.test.ts +++ b/packages/core/src/__tests__/get.iso.test.ts @@ -17,28 +17,42 @@ const obj = { } } -const fixtures: Record = { - '': obj, - a: obj.a, - 'a.b': obj.a.b, - 'a.b.c': obj.a.b.c, - 'a.b.d': obj.a.b.d, - 'a.b.e': obj.a.b.e, - 'a.b.f[0]': obj.a.b.f[0], - 'a.b.f[0].g': obj.a.b.f[0].g, - 'a.h': obj.a.h, - 'a.b.x': undefined, - u: undefined -} +// webkit does not support look behind ATM +const supportsLookBehind = (() => { + try { + new RegExp(`(?<=Y)`) + return true + } catch (e) { + return false + } +})() -/** note that this test is basically a duplicate of the get.test.ts file, - * only with the tests that safari can't handle due to its lack of lookbehind (ES2018) - * grouping removed so it passes in webkit */ +const fixtures = new Map([ + [undefined, undefined], + [null, undefined], + [['a', 'b'], obj.a.b], + ['', obj], + ['.', obj], + ['a', obj.a], + ['a.b', obj.a.b], + ["['a'].b", obj.a.b], + ['["a"].b', obj.a.b], + ['a.b.c', obj.a.b.c], + ['a.b.d', obj.a.b.d], + ['a.b.e', obj.a.b.e], + ['a.b.f[0]', obj.a.b.f[0]], + ['a.b.f[0].g', obj.a.b.f[0].g], + ['a.h', obj.a.h], + ['a.b.x', undefined], + ['u', undefined], + ['[txt] non', supportsLookBehind ? true : undefined], + ['[txt] nest.inner', supportsLookBehind ? true : undefined] +]) describe('get', () => { - for (const path of Object.keys(fixtures)) { + fixtures.forEach((expected, path) => { test(`"${path}"`, () => { - expect(get(obj, path)).toEqual(fixtures[path]) + expect(get(obj, path)).toEqual(expected) }) - } + }) }) diff --git a/packages/core/src/__tests__/get.test.ts b/packages/core/src/__tests__/get.test.ts deleted file mode 100644 index c42fcdb4f4..0000000000 --- a/packages/core/src/__tests__/get.test.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { get } from '../get' - -const obj = { - a: { - b: { - c: 42, - d: true, - e: 'hello', - f: [{ g: 'yay' }, { g: 'nay' }] - }, - h: null - }, - u: undefined, - '[txt] non': true, - '[txt] nest': { - inner: true - } -} - -const fixtures: Record = { - '': obj, - a: obj.a, - 'a.b': obj.a.b, - "['a'].b": obj.a.b, - '["a"].b': obj.a.b, - 'a.b.c': obj.a.b.c, - 'a.b.d': obj.a.b.d, - 'a.b.e': obj.a.b.e, - 'a.b.f[0]': obj.a.b.f[0], - 'a.b.f[0].g': obj.a.b.f[0].g, - 'a.h': obj.a.h, - 'a.b.x': undefined, - '[txt] non': true, - '[txt] nest.inner': true, - u: undefined -} - -describe('get', () => { - for (const path of Object.keys(fixtures)) { - test(`"${path}"`, () => { - expect(get(obj, path)).toEqual(fixtures[path]) - }) - } -})