MCPcopy Create free account
hub / github.com/observablehq/framework / assert

Method assert

src/error.ts:62–78  ·  view source on GitHub ↗

Use in tests to check if a thrown error is the error you expected.

(
    error: unknown,
    {message, exitCode = 1, print = true}: {message?: RegExp | string; exitCode?: number; print?: boolean} = {}
  )

Source from the content-addressed store, hash-verified

60
61 /** Use in tests to check if a thrown error is the error you expected. */
62 static assert(
63 error: unknown,
64 {message, exitCode = 1, print = true}: {message?: RegExp | string; exitCode?: number; print?: boolean} = {}
65 ): asserts error is CliError {
66 assert.ok(error instanceof Error, `Expected error to be an Error but got ${error}`);
67 assert.ok(error instanceof CliError, `Expected error to be a CliError but got ${error.message}\n${error.stack}`);
68 if (typeof message === "string") {
69 assert.equal(error.message, message);
70 } else if (message instanceof RegExp) {
71 assert.ok(
72 message.test(error.message),
73 `Expected error message to match regexp ${message.toString()} but got ${error.message}`
74 );
75 }
76 assert.equal(error.exitCode, exitCode, `Expected exit code to be ${exitCode}, but got ${error.exitCode}`);
77 assert.equal(error.print, print, `Expected print to be ${print}, but got ${error.print}`);
78 }
79
80 /** Use in tests to check if a thrown error is the error you expected. */
81 static match(

Callers 3

deploy-test.tsFile · 0.80

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected