Connectum API Reference / @connectum/testing / index / assertConnectError
Function: assertConnectError() ​
assertConnectError(
error,expectedCode,messagePattern?):asserts error is ConnectError
Defined in: test-fixtures/dist/index.d.ts:45
Assert that a thrown value is a ConnectError with the expected gRPC status code and, optionally, a message matching a pattern.
This is a TypeScript assertion function: after a successful call the compiler narrows error to ConnectError.
Note on message format: ConnectError messages include a code prefix, e.g. [not_found] user not found. A supplied messagePattern is matched against the full message, but matching is refused when it exceeds 1000 characters. Use a RegExp for flexible matching within that limit.
Parameters ​
error ​
unknown
The value to check (typically from a catch block).
expectedCode ​
Code
Expected gRPC/Connect status code.
messagePattern? ​
string | RegExp
Optional substring or RegExp to match against error.message.
Returns ​
asserts error is ConnectError
Throws ​
When any of the checks fail.
Example ​
import { Code, ConnectError } from "@connectrpc/connect";
import { assertConnectError } from "@connectum/testing";
try {
await client.getUser({ id: "missing" });
} catch (err) {
assertConnectError(err, Code.NotFound, "user not found");
// err is now typed as ConnectError
console.log(err.code); // Code.NotFound
}