From 8c952a10c38e8ac1075cd720f52be3830c61ec48 Mon Sep 17 00:00:00 2001 From: Luke Kuzmish Date: Tue, 7 Jan 2025 08:48:57 -0500 Subject: [PATCH] unstable stringify tests --- csv/unstable_stringify_test.ts | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/csv/unstable_stringify_test.ts b/csv/unstable_stringify_test.ts index 773bfec369cf..441d3da74a03 100644 --- a/csv/unstable_stringify_test.ts +++ b/csv/unstable_stringify_test.ts @@ -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"; @@ -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", + ); + }, + }, + ); });