@@ -122,4 +122,64 @@ describe(`filter`, () => {
122122 expect ( result ) . toEqual ( data . filter ( ( d ) => d . _id == 13 ) ) ;
123123 } ) ;
124124 } ) ;
125+
126+ describe ( 'filter array fields' , ( ) => {
127+ const data = [
128+ { id : 1 , tags : [ 'javascript' , 'typescript' ] } ,
129+ { id : 2 , tags : [ 'python' , 'typescript' ] } ,
130+ { id : 3 , tags : [ 'java' ] } ,
131+ { id : 4 , tags : [ ] } ,
132+ { id : 5 } ,
133+ ] ;
134+
135+ it ( 'should filter by array value' , ( ) => {
136+ const result = filter ( new QueryParser ( 'tags:typescript' ) , data ) ;
137+ expect ( result ) . toEqual ( [
138+ { id : 1 , tags : [ 'javascript' , 'typescript' ] } ,
139+ { id : 2 , tags : [ 'python' , 'typescript' ] } ,
140+ ] ) ;
141+ } ) ;
142+
143+ it ( 'should handle nested array fields' , ( ) => {
144+ const nestedData = [
145+ {
146+ id : 1 ,
147+ nested : {
148+ tags : [ 'javascript' , 'typescript' ] ,
149+ } ,
150+ } ,
151+ {
152+ id : 2 ,
153+ nested : {
154+ tags : [ 'python' ] ,
155+ } ,
156+ } ,
157+ {
158+ id : 3 ,
159+ nested : {
160+ other : [ 'something' ] ,
161+ } ,
162+ } ,
163+ ] ;
164+
165+ const queries = [
166+ 'nested.tags:typescript' , // explicit field path
167+ '*.tags:typescript' , // wildcard prefix
168+ 'nested.tags*:typescript' , // wildcard suffix
169+ '*.tags*:typescript' , // wildcard on both sides
170+ ] ;
171+
172+ for ( const query of queries ) {
173+ const result = filter ( new QueryParser ( query ) , nestedData ) ;
174+ expect ( result ) . toEqual ( [
175+ {
176+ id : 1 ,
177+ nested : {
178+ tags : [ 'javascript' , 'typescript' ] ,
179+ } ,
180+ } ,
181+ ] ) ;
182+ }
183+ } ) ;
184+ } ) ;
125185} ) ;
0 commit comments