Skip to content

Commit

Permalink
unstable stringify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmastech committed Jan 10, 2025
1 parent 2604b37 commit 8c952a1
Showing 1 changed file with 61 additions and 0 deletions.
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",
);
},
},
);
});

0 comments on commit 8c952a1

Please sign in to comment.