@@ -8,13 +8,13 @@ describe('Write object records into CSV', () => {
8
8
9
9
const makeFilePath = ( id : string ) => testFilePath ( `object-${ id } ` ) ;
10
10
const records = [
11
- { name : 'Bob' , lang : 'French' } ,
12
- { name : 'Mary' , lang : 'English' }
11
+ { name : 'Bob' , lang : 'French' , address : { country : 'France' } } ,
12
+ { name : 'Mary' , lang : 'English' , address : { country : 'Australia' } }
13
13
] ;
14
14
15
15
describe ( 'When only path and header ids are given' , ( ) => {
16
16
const filePath = makeFilePath ( 'minimum' ) ;
17
- let writer : CsvWriter < ObjectMap < string > > ;
17
+ let writer : CsvWriter < ObjectMap < string | ObjectMap < string > > > ;
18
18
19
19
beforeEach ( ( ) => {
20
20
writer = createObjectCsvWriter ( {
@@ -50,7 +50,7 @@ describe('Write object records into CSV', () => {
50
50
51
51
describe ( 'When field header is given with titles' , ( ) => {
52
52
const filePath = makeFilePath ( 'header' ) ;
53
- let writer : CsvWriter < ObjectMap < string > > ;
53
+ let writer : CsvWriter < ObjectMap < string | ObjectMap < string > > > ;
54
54
55
55
beforeEach ( ( ) => {
56
56
writer = createObjectCsvWriter ( {
@@ -141,4 +141,18 @@ describe('Write object records into CSV', () => {
141
141
assertFile ( filePath , '"NAME","LANGUAGE"\n"Bob","French"\n"Mary","English"\n' ) ;
142
142
} ) ;
143
143
} ) ;
144
+
145
+ describe ( 'When `keyDelimiter` flag is set' , ( ) => {
146
+ const filePath = makeFilePath ( 'nested' ) ;
147
+ const writer = createObjectCsvWriter ( {
148
+ path : filePath ,
149
+ header : [ { id : 'name' , title : 'NAME' } , { id : 'address.country' , title : 'COUNTRY' } ] ,
150
+ keyDelimiter : '.'
151
+ } ) ;
152
+
153
+ it ( 'breaks keys into key paths' , async ( ) => {
154
+ await writer . writeRecords ( records ) ;
155
+ assertFile ( filePath , 'NAME,COUNTRY\nBob,France\nMary,Australia\n' ) ;
156
+ } ) ;
157
+ } ) ;
144
158
} ) ;
0 commit comments