a reactive (signals based) hypermedia web framework (wip)
stormlightlabs.github.io/volt/
hypermedia
frontend
signals
1import { echo } from "$utils/echo.js";
2import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
4describe("echo utility", () => {
5 let consoleLogSpy: ReturnType<typeof vi.spyOn>;
6 let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
7 let consoleWarnSpy: ReturnType<typeof vi.spyOn>;
8
9 beforeEach(() => {
10 consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {});
11 consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
12 consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
13 });
14
15 afterEach(() => {
16 consoleLogSpy.mockRestore();
17 consoleErrorSpy.mockRestore();
18 consoleWarnSpy.mockRestore();
19 });
20
21 describe("err", () => {
22 it("should log to stderr", () => {
23 echo.err("Error message");
24 expect(consoleErrorSpy).toHaveBeenCalledWith(expect.any(String));
25 });
26
27 it("should accept additional parameters", () => {
28 echo.err("Error:", "details", 123);
29 expect(consoleErrorSpy).toHaveBeenCalledWith(expect.any(String), "details", 123);
30 });
31 });
32
33 describe("danger", () => {
34 it("should log to stdout", () => {
35 echo.danger("Danger message");
36 expect(consoleLogSpy).toHaveBeenCalledWith(expect.any(String));
37 });
38 });
39
40 describe("ok", () => {
41 it("should log success message", () => {
42 echo.ok("Success message");
43 expect(consoleLogSpy).toHaveBeenCalledWith(expect.any(String));
44 });
45 });
46
47 describe("success", () => {
48 it("should log bold success message", () => {
49 echo.success("Success!");
50 expect(consoleLogSpy).toHaveBeenCalledWith(expect.any(String));
51 });
52 });
53
54 describe("info", () => {
55 it("should log info message", () => {
56 echo.info("Info message");
57 expect(consoleLogSpy).toHaveBeenCalledWith(expect.any(String));
58 });
59 });
60
61 describe("label", () => {
62 it("should log label message", () => {
63 echo.label("Label");
64 expect(consoleLogSpy).toHaveBeenCalledWith(expect.any(String));
65 });
66 });
67
68 describe("title", () => {
69 it("should log bold title", () => {
70 echo.title("Title");
71 expect(consoleLogSpy).toHaveBeenCalledWith(expect.any(String));
72 });
73 });
74
75 describe("warn", () => {
76 it("should log warning", () => {
77 echo.warn("Warning message");
78 expect(consoleWarnSpy).toHaveBeenCalledWith(expect.any(String));
79 });
80 });
81
82 describe("text", () => {
83 it("should be a reference to console.log", () => {
84 expect(typeof echo.text).toBe("function");
85 });
86 });
87});