Skip to content

Commit

Permalink
Refactor .get test (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky authored Jan 26, 2023
1 parent fd54f66 commit 7d29962
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 64 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ package-lock.json
.env
# JetBrains byproduct
.idea
coverage
coverage

# playwright
playwright-report
52 changes: 33 additions & 19 deletions packages/core/src/__tests__/get.iso.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,42 @@ const obj = {
}
}

const fixtures: Record<string, unknown> = {
'': 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<any, any>([
[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)
})
}
})
})
44 changes: 0 additions & 44 deletions packages/core/src/__tests__/get.test.ts

This file was deleted.

0 comments on commit 7d29962

Please sign in to comment.