Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to ensure spaces in headers and values are allowed #102

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions integration/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
percentage: 0.4,
quoted: '"Pickles"',
nullish: null,
"string with spaces as header": "value with spaces",
},
{
name: "Keiko",
date: "2023-09-01",
percentage: 0.9,
quoted: '"Cactus"',
nullish: "test",
"string with spaces as header": "more spaces",
},
];

Expand All @@ -56,6 +58,7 @@
);
</script>
</head>

<body>
<h1>Export to CSV testing</h1>
<button id="csv">Download as CSV</button>
Expand Down
32 changes: 32 additions & 0 deletions lib/__specs__/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,38 @@ describe("ExportToCsv", () => {
expect(typeof string === "string").toBeTruthy();
});

it("should allow keys with spaces", () => {
const mockDataOne = [
{
"Hello world": "test",
"this is another string with many spaces": 10,
},
];

const optionsOne = mkConfig({ useBom: false, useKeysAsHeaders: true });
const stringOne = asString(generateCsv(optionsOne)(mockDataOne));
expect(stringOne).toEqual(
'"Hello world","this is another string with many spaces"\r\n"test",10\r\n',
);

const mockDataTwo = [
{
"Hello world": "test",
"this is another string with many spaces": 10,
},
];

const optionsTwo = mkConfig({
useBom: false,
showColumnHeaders: true,
columnHeaders: ["Hello world", "this is another string with many spaces"],
});
const stringTwo = asString(generateCsv(optionsTwo)(mockDataTwo));
expect(stringTwo).toEqual(
'"Hello world","this is another string with many spaces"\r\n"test",10\r\n',
);
});

it("should use fieldSeparator if supplied", () => {
const options: ConfigOptions = {
title: "Test Csv",
Expand Down
Loading