Files
sendou.ink/app/features/dev-tools/core/ConsoleCapture.test.ts
Kalle f7372324fe
Some checks failed
E2E Tests / e2e (push) Has been cancelled
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled
E2E Tests / publish-docs-screenshots (push) Has been cancelled
Dev tools (#3471)
2026-10-25 11:43:36 +02:00

38 lines
1.1 KiB
TypeScript

import { describe, expect, test } from "vitest";
import * as ConsoleCapture from "./ConsoleCapture";
describe("ConsoleCapture.formatConsoleArgs", () => {
test.each([
{ why: "plain strings", args: ["a", "b"], expected: "a b" },
{
why: "%s substitutions",
args: ["Warning: %s is %s", "key", "missing"],
expected: "Warning: key is missing",
},
{
why: "%c styles dropped",
args: ["%cstyled", "color: red"],
expected: "styled",
},
{ why: "escaped percent", args: ["100%%"], expected: "100%" },
{
why: "extra args appended",
args: ["%s!", "hi", { a: 1 }],
expected: 'hi! {"a":1}',
},
{ why: "non-string first arg", args: [1, true], expected: "1 true" },
])("$why", ({ args, expected }) => {
expect(ConsoleCapture.formatConsoleArgs(args)).toBe(expected);
});
});
describe("ConsoleCapture.isHydrationMessage", () => {
test.each([
["A tree hydrated but some attributes didn't match", true],
["Hydration failed because the server rendered HTML", true],
["Each child in a list should have a unique key", false],
])("%s", (message, expected) => {
expect(ConsoleCapture.isHydrationMessage(message)).toBe(expected);
});
});