Inline assertions for t-req using # @assert ... directives in .http files.
npm install @t-req/plugin-assert
# or
bun add @t-req/plugin-assert
yarn add @t-req/plugin-assert
pnpm add @t-req/plugin-assertAdd to treq.jsonc:
Or load ad-hoc:
treq run ./requests/user.http --plugin @t-req/plugin-assert# @assert status == 200
# @assert header Content-Type contains application/json
# @assert body contains "ok"
# @assert jsonpath $.token exists
GET https://api.example.com/healthSupported targets:
| Target | Operators | Example |
|---|---|---|
status |
== != > >= < <= |
# @assert status == 200 |
header <name> |
exists == != contains |
# @assert header X-Trace-Id exists |
body |
contains not-contains |
# @assert body not-contains "error" |
jsonpath <expr> |
exists == != |
# @assert jsonpath $.count == 2 |
- Assertions run in
response.after. - One summary report is emitted per request with:
kind: "assert"passed: booleantotal,failedchecks[]details
- Any failed assertion sets
passed: false, andtreq runexits with code1. - Malformed assertions also fail the run (fail-fast behavior).
treq validate uses this plugin's validate hook to surface assertion issues early:
assert.syntaxassert.operatorassert.targetassert.missing-valueassert.invalid-jsonpathassert.position
Example:
treq validate ./requestsMIT
{ "plugins": ["@t-req/plugin-assert"] }