From 5d60561f7b5f839b3e142f60d5e7188ee7ed7fc8 Mon Sep 17 00:00:00 2001 From: abdennour Date: Fri, 25 Nov 2016 18:32:24 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=94age=20more=20than=2085%=20?= =?UTF-8?q?=F0=9F=91=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/coreSpec.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/coreSpec.js b/test/coreSpec.js index fc04c63..839fb5e 100644 --- a/test/coreSpec.js +++ b/test/coreSpec.js @@ -177,5 +177,29 @@ describe(`core::jsons2csv`, () => { expect(actual).toBeA('string'); expect(actual.split(`\n`).join(`|`)).toEqual(expected); }); + it(`renders CSV string according to order of given headers`, () => { + let fixtures =[{X:'12', Y:'bb'}, {Y:'ee', X:'55'}] + const headers = ['Y', 'X', 'Z']; + const actual = jsons2csv(fixtures, headers); + expect(actual.startsWith(headers.join(`,`))).toBeTruthy(); + expect(actual.endsWith(`ee,55,`)).toBeTruthy(); + + }); + +}); + +describe(`core::string2csv`, () =>{ + let fixtures; + beforeEach(() => { + fixtures = `33,44\n55,66`; + }); + it(`returns the same string if no header given`, () => { + expect(string2csv(fixtures)).toEqual(fixtures); + }) + + it(`prepends headers at the top of input`, () => { + const headers =[`X`, `Y`]; + expect(string2csv(fixtures, headers)).toEqual(`${headers.join(`,`)}\n${fixtures}`); + }) });