File size: 602 Bytes
31b3c47
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
import assert from "node:assert/strict";
import { test } from "node:test";
import { errorMessage } from "./error-message.ts";

test("router error text admits real Error objects only", () => {
  assert.equal(errorMessage(new Error("Request failed")), "Request failed");
  const fallback = "An unexpected error occurred. Try reloading the page.";
  for (const value of [undefined, null, 0, "untrusted", { message: "untrusted" }, new Error("")]) {
    assert.equal(errorMessage(value), fallback);
  }
  assert.equal(errorMessage({ get message() { throw new Error("must not be read"); } }), fallback);
});