mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
test: cover readSize branches in Context
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -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] () {
|
||||
|
||||
Reference in New Issue
Block a user