mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 15:00:42 -07:00
test(context): cover Object.prototype keys under ownPropertyOnly
- Add getSync cases for constructor and valueOf on plain objects - Remove scope storage tests that used the in operator Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -138,6 +138,11 @@ describe('Context', function () {
|
|||||||
ctx.push({ foo: [] })
|
ctx.push({ foo: [] })
|
||||||
return expect(ctx.getSync(['foo', 'reduce'])).toEqual(undefined)
|
return expect(ctx.getSync(['foo', 'reduce'])).toEqual(undefined)
|
||||||
})
|
})
|
||||||
|
it('should return undefined for typical Object.prototype properties (e.g. constructor, valueOf)', function () {
|
||||||
|
ctx.push({ obj: {} })
|
||||||
|
expect(ctx.getSync(['obj', 'constructor'])).toEqual(undefined)
|
||||||
|
expect(ctx.getSync(['obj', 'valueOf'])).toEqual(undefined)
|
||||||
|
})
|
||||||
it('should return undefined for function prototype property', function () {
|
it('should return undefined for function prototype property', function () {
|
||||||
function Foo () {}
|
function Foo () {}
|
||||||
Foo.prototype.bar = 'BAR'
|
Foo.prototype.bar = 'BAR'
|
||||||
@@ -216,17 +221,4 @@ describe('Context', function () {
|
|||||||
expect(ctx.getSync(['foo'])).toEqual('zoo')
|
expect(ctx.getSync(['foo'])).toEqual('zoo')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
describe('scope storage', function () {
|
|
||||||
it('should not treat Object.prototype properties as implicit keys on bottom scope', function () {
|
|
||||||
const bottom = new Context().bottom() as Record<string, unknown>
|
|
||||||
expect('toString' in bottom).toBe(false)
|
|
||||||
expect('hasOwnProperty' in bottom).toBe(false)
|
|
||||||
})
|
|
||||||
it('should merge into a scope result without implicit Object.prototype keys', function () {
|
|
||||||
const all = new Context({ a: 1 }).getAll() as Record<string, unknown>
|
|
||||||
expect(all.a).toBe(1)
|
|
||||||
expect('toString' in all).toBe(false)
|
|
||||||
expect('hasOwnProperty' in all).toBe(false)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user