@@ -242,5 +242,77 @@ describe('API testing', function () {
242242
243243 } ) ;
244244
245+ describe ( 'indexHeader() multiple files test' , function ( ) {
246+ beforeEach ( function ( ) {
247+ // Reset all configurations before each test using chaining pattern
248+ index
249+ . formatValueByType ( false )
250+ . fieldDelimiter ( ';' )
251+ . indexHeader ( 0 )
252+ . supportQuotedField ( false )
253+ . trimHeaderFieldWhiteSpace ( false ) ;
254+ } ) ;
255+
256+ it ( 'should handle multiple files with different indexHeader values without throwing error' , function ( ) {
257+ //given
258+ const files = [
259+ { path : 'test/resource/input_header_row0.csv' , headerIndex : 0 , expectedLength : 2 } ,
260+ { path : 'test/resource/input_header_row1.csv' , headerIndex : 1 , expectedLength : 2 } ,
261+ { path : 'test/resource/input_header_row2.csv' , headerIndex : 2 , expectedLength : 2 }
262+ ] ;
263+
264+ //when & then - process each file with different indexHeader
265+ files . forEach ( file => {
266+ const result = index
267+ . fieldDelimiter ( ',' )
268+ . indexHeader ( file . headerIndex )
269+ . getJsonFromCsv ( file . path ) ;
270+
271+ expect ( result ) . toBeDefined ( ) ;
272+ expect ( Array . isArray ( result ) ) . toBe ( true ) ;
273+ expect ( result . length ) . toEqual ( file . expectedLength ) ;
274+
275+ // Reset state after each file to ensure clean state using chaining pattern
276+ index
277+ . fieldDelimiter ( ';' )
278+ . indexHeader ( 0 ) ;
279+ } ) ;
280+ } ) ;
281+
282+ it ( 'should process same file multiple times with different indexHeader values' , function ( ) {
283+ //given
284+ const file = 'test/resource/input_header_row0.csv' ;
285+
286+ //when & then - process same file multiple times using chaining pattern
287+ const result1 = index
288+ . fieldDelimiter ( ',' )
289+ . indexHeader ( 0 )
290+ . getJsonFromCsv ( file ) ;
291+
292+ expect ( result1 . length ) . toEqual ( 2 ) ;
293+ expect ( result1 [ 0 ] ) . toHaveProperty ( 'name' ) ;
294+ expect ( result1 [ 0 ] ) . toHaveProperty ( 'age' ) ;
295+ expect ( result1 [ 0 ] ) . toHaveProperty ( 'city' ) ;
296+
297+ // Reset and process the same file again - this should not throw an error using chaining pattern
298+ const result2 = index
299+ . fieldDelimiter ( ',' )
300+ . indexHeader ( 0 )
301+ . getJsonFromCsv ( file ) ;
302+
303+ expect ( result2 . length ) . toEqual ( 2 ) ;
304+ expect ( result2 [ 0 ] ) . toHaveProperty ( 'name' ) ;
305+ } ) ;
306+
307+ afterEach ( function ( ) {
308+ // Reset all configurations after each test using chaining pattern
309+ index
310+ . formatValueByType ( false )
311+ . fieldDelimiter ( ';' )
312+ . indexHeader ( 0 )
313+ . supportQuotedField ( false )
314+ . trimHeaderFieldWhiteSpace ( false ) ;
315+ } ) ;
316+ } ) ;
245317
246318} ) ;
0 commit comments