From e8d5487a436e53e78f55d58d77c732000aa0e87e Mon Sep 17 00:00:00 2001 From: Yang Jun Date: Fri, 24 Jul 2026 00:49:10 +0800 Subject: [PATCH] test: cover readSize branches in Context Co-authored-by: Cursor --- src/context/context.spec.ts | 7 +++++++ test/integration/liquid/scope-security.spec.ts | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/context/context.spec.ts b/src/context/context.spec.ts index 839810c8e..b26575f82 100644 --- a/src/context/context.spec.ts +++ b/src/context/context.spec.ts @@ -58,6 +58,9 @@ describe('Context', function () { it('should return map size as size', async function () { expect(ctx.get(['map', 'size'])).toEqual(1) }) + it('should return own size property', async function () { + expect(ctx.get(['zoo', 'size'])).toEqual(4) + }) it('should return undefined if not have a size', async function () { expect(ctx.get(['one', 'size'])).toBeUndefined() expect(ctx.get(['non-exist', 'size'])).toBeUndefined() @@ -130,6 +133,10 @@ describe('Context', function () { ctx = new Context({ foo: Object.create({ bar: 'BAR' }) }, { ownPropertyOnly: false } as any) return expect(ctx.getSync(['foo', 'bar'])).toEqual('BAR') }) + it('should read inherited size when ownPropertyOnly=false', function () { + ctx = new Context({ foo: Object.create({ size: 99 }) }, { ownPropertyOnly: false } as any) + return expect(ctx.getSync(['foo', 'size'])).toEqual(99) + }) it('renderOptions.ownPropertyOnly should override options.ownPropertyOnly', function () { ctx = new Context({ foo: Object.create({ bar: 'BAR' }) }, { ownPropertyOnly: false } as any, { ownPropertyOnly: true }) return expect(ctx.getSync(['foo', 'bar'])).toEqual(undefined) diff --git a/test/integration/liquid/scope-security.spec.ts b/test/integration/liquid/scope-security.spec.ts index 2475421d7..bb1eb474f 100644 --- a/test/integration/liquid/scope-security.spec.ts +++ b/test/integration/liquid/scope-security.spec.ts @@ -27,6 +27,12 @@ describe('scope security', function () { await expect(liquid.parseAndRender('{{ obj.size }}', { obj })).resolves.toBe('1') }) + it('should read inherited size when ownPropertyOnly=false', async function () { + liquid = new Liquid({ ownPropertyOnly: false }) + const obj = Object.create({ size: 99 }) + await expect(liquid.parseAndRender('{{ obj.size }}', { obj })).resolves.toBe('99') + }) + it('should still iterate Drop with Symbol.iterator', async function () { class IterableDrop extends Drop { * [Symbol.iterator] () {