fix: for tag not respecting Drop#valueOf(), fixes #515

This commit is contained in:
Harttle
2022-07-09 22:21:51 +08:00
parent a19feea7c4
commit c3e51caa70
6 changed files with 15 additions and 18 deletions
+1 -2
View File
@@ -324,8 +324,7 @@ describe('tags/for', function () {
yield 'b'
yield 'c'
}
public valueOf (): string {
toString () {
return 'MockIterableDrop'
}
}
+11
View File
@@ -61,4 +61,15 @@ describe('drop/drop', function () {
const html = await liquid.parseAndRender(`{{obj.foo}}`, { obj: new PromiseDrop() })
expect(html).to.equal('FOO')
})
it('should respect valueOf', async () => {
class CustomDrop extends Drop {
prop = 'not enumerable'
valueOf () {
return ['foo', 'bar']
}
}
const tpl = '{{drop}}: {% for field in drop %}{{ field }};{% endfor %}'
const html = await liquid.parseAndRender(tpl, { drop: new CustomDrop() })
expect(html).to.equal('foobar: foo;bar;')
})
})
-10
View File
@@ -1,10 +0,0 @@
import { expect } from 'chai'
import { Drop } from '../../../src/drop/drop'
describe('drop/drop', function () {
class CustomDrop extends Drop { }
it('.valueOf() should return undefined by default', async function () {
expect(new CustomDrop().valueOf()).to.be.undefined
})
})