test: cover readSize branches in Context

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Yang Jun
2026-07-24 00:49:10 +08:00
co-authored by Cursor
parent 6f8224d286
commit e8d5487a43
2 changed files with 13 additions and 0 deletions
+7
View File
@@ -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)
@@ -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] () {