@@ -7,14 +7,14 @@ describe('filter', function () {
7
7
const ctx = new Context ( { thirty : 30 } )
8
8
const liquid = { testVersion : '1.0' } as any
9
9
it ( 'should not change input if filter not registered' , async function ( ) {
10
- const filter = new Filter ( 'foo' , undefined as any , [ ] , liquid )
10
+ const filter = new Filter ( { name : 'foo' , args : [ ] } as any , undefined as any , liquid )
11
11
expect ( await toPromise ( filter . render ( 'value' , ctx ) ) ) . toBe ( 'value' )
12
12
} )
13
13
14
14
it ( 'should call filter impl with correct arguments' , async function ( ) {
15
15
const spy = jest . fn ( )
16
16
const thirty = new NumberToken ( '30' , 0 , 2 , undefined )
17
- const filter = new Filter ( 'foo' , spy , [ thirty ] , liquid )
17
+ const filter = new Filter ( { name : 'foo' , args : [ thirty ] } as any , spy , liquid )
18
18
await toPromise ( filter . render ( 'foo' , ctx ) )
19
19
expect ( spy ) . toHaveBeenCalledWith ( 'foo' , 30 )
20
20
} )
@@ -24,37 +24,37 @@ describe('filter', function () {
24
24
return `${ this . liquid . testVersion } : ${ val + diff } `
25
25
} )
26
26
const ten = new NumberToken ( '10' , 0 , 2 , undefined )
27
- const filter = new Filter ( 'add' , spy , [ ten ] , liquid )
27
+ const filter = new Filter ( { name : 'add' , args : [ ten ] } as any , spy , liquid )
28
28
const val = await toPromise ( filter . render ( 'thirty' , ctx ) )
29
29
expect ( val ) . toEqual ( '1.0: 40' )
30
30
} )
31
31
it ( 'should render a simple filter' , async function ( ) {
32
- expect ( await toPromise ( new Filter ( 'upcase' , ( x : string ) => x . toUpperCase ( ) , [ ] , liquid ) . render ( 'foo' , ctx ) ) ) . toBe ( 'FOO' )
32
+ expect ( await toPromise ( new Filter ( { name : 'upcase' , args : [ ] } as any , ( x : string ) => x . toUpperCase ( ) , liquid ) . render ( 'foo' , ctx ) ) ) . toBe ( 'FOO' )
33
33
} )
34
34
it ( 'should reject promise when filter throws' , async function ( ) {
35
- const filter = new Filter ( 'foo' , function * ( ) { throw new Error ( 'intended' ) } , [ ] , liquid )
35
+ const filter = new Filter ( { name : 'foo' , args : [ ] } as any , function * ( ) { throw new Error ( 'intended' ) } , liquid )
36
36
expect ( toPromise ( filter . render ( 'foo' , ctx ) ) ) . rejects . toMatchObject ( {
37
37
message : 'intended'
38
38
} )
39
39
} )
40
40
it ( 'should render filters with argument' , async function ( ) {
41
41
const two = new NumberToken ( '2' , 0 , 1 , undefined )
42
- expect ( await toPromise ( new Filter ( 'add' , ( a : number , b : number ) => a + b , [ two ] , liquid ) . render ( 3 , ctx ) ) ) . toBe ( 5 )
42
+ expect ( await toPromise ( new Filter ( { name : 'add' , args : [ two ] } as any , ( a : number , b : number ) => a + b , liquid ) . render ( 3 , ctx ) ) ) . toBe ( 5 )
43
43
} )
44
44
45
45
it ( 'should render filters with multiple arguments' , async function ( ) {
46
46
const two = new NumberToken ( '2' , 0 , 1 , undefined )
47
47
const c = new QuotedToken ( '"c"' , 0 , 3 )
48
- expect ( await toPromise ( new Filter ( 'add' , ( a : number , b : number , c : number ) => a + b + c , [ two , c ] , liquid ) . render ( 3 , ctx ) ) ) . toBe ( '5c' )
48
+ expect ( await toPromise ( new Filter ( { name : 'add' , args : [ two , c ] } as any , ( a : number , b : number , c : number ) => a + b + c , liquid ) . render ( 3 , ctx ) ) ) . toBe ( '5c' )
49
49
} )
50
50
51
51
it ( 'should pass Objects/Drops as it is' , async function ( ) {
52
52
class Foo { }
53
- expect ( await toPromise ( new Filter ( 'name' , ( a : any ) => a . constructor . name , [ ] , liquid ) . render ( new Foo ( ) , ctx ) ) ) . toBe ( 'Foo' )
53
+ expect ( await toPromise ( new Filter ( { name : 'name' , args : [ ] } as any , ( a : any ) => a . constructor . name , liquid ) . render ( new Foo ( ) , ctx ) ) ) . toBe ( 'Foo' )
54
54
} )
55
55
56
56
it ( 'should support key value pairs' , async function ( ) {
57
57
const two = new NumberToken ( '2' , 0 , 1 , undefined )
58
- expect ( await toPromise ( new Filter ( 'add' , ( a : number , b : number [ ] ) => b [ 0 ] + ':' + ( a + b [ 1 ] ) , [ [ 'num' , two ] ] , liquid ) . render ( 3 , ctx ) ) ) . toBe ( 'num:5' )
58
+ expect ( await toPromise ( new Filter ( { name : 'add' , args : [ [ 'num' , two ] ] } as any , ( a : number , b : number [ ] ) => b [ 0 ] + ':' + ( a + b [ 1 ] ) , liquid ) . render ( 3 , ctx ) ) ) . toBe ( 'num:5' )
59
59
} )
60
60
} )
0 commit comments