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

test(csv): unstable stringify tests #6337

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
61 changes: 61 additions & 0 deletions csv/unstable_stringify_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { assertEquals } from "@std/assert/equals";
import { stringify } from "./unstable_stringify.ts";
import { assertThrows } from "../assert/throws.ts";

const CRLF = "\r\n";

Expand All @@ -28,4 +29,64 @@ Deno.test("(unstable) stringify", async (t) => {
},
},
);

await t.step(
{
name: "options.columns is a bool",
fn() {
const options = { columns: true };
const data = [{ a: 1 }];
assertThrows(
// @ts-ignore: for test
() => stringify(data, options),
"Cannot stringify data as the columns option is invalid: columns must be an array or undefined",
);
},
},
);

await t.step(
{
name: "options.columns is an object",
fn() {
const options = { columns: { v: true } };
const data = [{ a: 1 }];
assertThrows(
// @ts-ignore: for test
() => stringify(data, options),
"Cannot stringify data as the columns option is invalid: columns must be an array or undefined",
);
},
},
);

await t.step(
{
name: "options.columns is a number",
fn() {
const options = { columns: 127 };
const data = [{ a: 1 }];
assertThrows(
// @ts-ignore: for test
() => stringify(data, options),
"Cannot stringify data as the columns option is invalid: columns must be an array or undefined",
);
},
},
);

await t.step(
{
name: "options.columns is a string",
fn() {
const options = { columns: "i am a string" };
const data = [{ a: 1 }];
assertThrows(
// @ts-ignore: for test
() => stringify(data, options),
"Cannot stringify data as the columns option is invalid: columns must be an array or undefined",
);
},
},
);
});
Loading