mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
fix: isComparable full interface check (#701)
* Improve isComparable function to ensure full Comparable interface implementation * Deleted trailing commas --------- Co-authored-by: Guillermo Casal Caro <[email protected]>
This commit is contained in:
co-authored by
Guillermo Casal Caro
parent
6ca5376362
commit
55e144a029
@@ -9,5 +9,12 @@ export interface Comparable {
|
||||
}
|
||||
|
||||
export function isComparable (arg: any): arg is Comparable {
|
||||
return arg && isFunction(arg.equals)
|
||||
return (
|
||||
arg &&
|
||||
isFunction(arg.equals) &&
|
||||
isFunction(arg.gt) &&
|
||||
isFunction(arg.geq) &&
|
||||
isFunction(arg.lt) &&
|
||||
isFunction(arg.leq)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -83,6 +83,26 @@ describe('drop/drop', function () {
|
||||
const html = await liquid.parseAndRender(tpl, { address, customer })
|
||||
expect(html).toBe('test')
|
||||
})
|
||||
it('should correctly evaluate custom Drop objects with equals function without full Comparable implementation', async () => {
|
||||
class TestDrop extends Drop {
|
||||
value: string;
|
||||
constructor () {
|
||||
super()
|
||||
this.value = 'test'
|
||||
}
|
||||
equals (rhs: string): boolean {
|
||||
return this.valueOf() === rhs
|
||||
}
|
||||
valueOf (): string {
|
||||
return this.value
|
||||
}
|
||||
}
|
||||
const address = new TestDrop()
|
||||
const customer = { default_address: new TestDrop() }
|
||||
const tpl = `{{ address >= customer.default_address }}`
|
||||
const html = await liquid.parseAndRender(tpl, { address, customer })
|
||||
expect(html).toBe('true')
|
||||
})
|
||||
it('should support returning supported value types from liquidMethodMissing', async function () {
|
||||
class DynamicTypeDrop extends Drop {
|
||||
liquidMethodMissing (key: string) {
|
||||
|
||||
Reference in New Issue
Block a user