Skip to content

Checking the Response ​

Checks (called assertions in the editor) decide whether a suite passes. After the route answers, every check runs. The suite passes only if all of them hold.

A suite with no checks passes as long as the route runs without crashing.

Simple checks ​

Open the Assertions tab, press Add assertion, and pick a target:

TargetWhat it looks atExtra field
Status codeThe HTTP status, for example 200 or 404—
Response bodyThe whole body, or one value inside itProperty path (optional)
HeaderOne response header. The name is not case-sensitiveHeader name
Duration (ms)How long the route took, in milliseconds—
Custom JSAnything you like, written in JavaScriptSee below

Instead of writing a body check by hand, you can tick Response body matches the route's saved schema. See Check the body against a saved schema.

Then pick an operator and, if it needs one, an expected value:

OperatorPasses when the value…Works with
equalsis exactly the expected valueall
not equalsis anything but the expected valueall
less thanis smaller than the expected numberStatus code, Duration
greater thanis bigger than the expected numberStatus code, Duration
containshas the expected text somewhere in itResponse body, Header
is true / is falseis true / falseResponse body, Header
existsis present (not missing and not null)Response body, Header
does not existis missing or nullResponse body, Header

Workflow suites have their own targets (Run succeeded and Output). See Testing workflows.

How values are compared ​

The expected value is always typed as text. The check compares it like this:

TargetHow it compares
Status code, DurationAs numbers, so 200 equals 200.0
Response body, Header, OutputAs text. A number or true/false in the body is turned into text first, so 42 equals the number 42
An object or a listAs compact JSON, with no spaces: {"id":42,"name":"Ada"}

So equals on a whole object is easy to get wrong: key order and spaces must match exactly. Check one value with a property path instead, or use a Custom JS check with toEqual.

contains looks for the expected text inside the value. For an object or a list it looks inside its JSON, so contains "admin" passes for { "tags": ["admin"] }.

is true also passes for the text "true"; is false for the text "false".

Check the body against a saved schema ​

If the route has a response schema, tick Response body matches the route's saved schema at the top of the Assertions tab. You do not have to write the body check again.

SituationResult
The body fits the schema saved for the status the route answeredThe check passes
A field is missing, or has the wrong typeThe check fails and names each field (up to five)
The route answered a status that has no saved schemaThe check fails and says so. Save a schema for that status first
  • The check follows the route. It reads the saved schema each time the suite runs, so editing the schema in the playground changes what the suite checks. A production run uses the schema saved in the promoted version.
  • The status code is the one the route actually answered, so a 404 is judged by the 404 schema.
  • Untick the box to remove the check. It does not appear in the assertion list below the checkbox.

Reading a failed check ​

A failed simple check says what it expected and what it actually found:

text
Expected Body(success) to false , got: (property not found: success). body has: message, errors
What was foundHow it is shown
A path that doesn't exist(property not found: success), then what is there instead: body has: message, errors. For a nested path the first missing step is named: (property not found: user.address). user has: name, age
A body that is a list or plain textbody is a list of 2 items or body is "Not Found"
No body at all(no body)
nullnull
TextIn quotes, so an empty text reads ""
A number or true/falseAs it is
An object or a listAs JSON. Anything over 300 characters is cut with … and its full length

The same text shows in the results screen and in the AI assistant's test results.

Property paths ​

A property path picks one value out of the body. Use dots for objects and [n] for list positions (counting from 0).

For this body:

json
{ "user": { "name": "Ada", "tags": ["admin", "beta"] } }
Property pathValue
(empty)the whole body
user.name"Ada"
user.tags[1]"beta"
user.tags["admin","beta"]
user.agemissing, so only does not exist passes

Example: a full set of simple checks ​

For a route that answers 201 with { "id": 7, "email": "[email protected]", "roles": ["user"] }:

TargetProperty path / Header nameOperatorExpected value
Status codeequals201
Duration (ms)less than500
Headercontent-typecontainsapplication/json
Response bodyidexists
Response bodyemailcontains@example.com
Response bodyrolesequals["user"]
Response bodypassworddoes not exist

Custom JS checks ​

When a simple check is not enough, choose Custom JS and write checks in JavaScript with t.expect:

js
t.expect(fluxify.response.status).toBe(201);
t.expect(fluxify.response.body.user.email).toContain("@");
t.expect(fluxify.response.body.items).toHaveLength(3);

Each t.expect(...) line shows up as its own line in the results, so a failure tells you exactly what went wrong:

text
✗ expected 500 to be 201

Give a check a name as the second argument to make results easier to read:

js
t.expect(fluxify.response.status, "status").toBe(201);
// ✗ status: expected 500 to be 201

At least one check

A Custom JS assertion must call t.expect at least once. One that does not fails with "Custom JS made no t.expect(...) checks". Returning true or false does nothing.

A failed check does not stop your code: every t.expect line runs and is reported. If your code throws an error instead, the assertion fails with that error.

What you can read ​

NameWhat it is
fluxify.response.statusThe status code
fluxify.response.bodyThe body the route returned
fluxify.response.headersThe response headers (names in lower case)
fluxify.request.pathThe path that was called, with path values filled in
fluxify.request.paramsThe path values, for example { id: "42" }
fluxify.request.queryThe query values
fluxify.request.headersThe request headers
fluxify.request.bodyThe request body
t.setupWhat the suite's setup block returned, if it has one
t.zodThe zod library, to check the shape of a value (see below)

t.expect checks ​

CheckPasses when the value…Example
.toBe(x)is exactly x (same number, text, true/false)t.expect(status).toBe(200)
.toEqual(x)has the same content as x, including inside objects and listst.expect(body).toEqual({ ok: true })
.toBeTruthy()counts as true (not 0, "", null, undefined, false)t.expect(body.id).toBeTruthy()
.toBeFalsy()counts as falset.expect(body.error).toBeFalsy()
.toBeNull()is null
.toBeUndefined()is undefined
.toBeDefined()is not undefined
.toContain(x)is text containing x, or a list containing xt.expect(body.tags).toContain("admin")
.toHaveLength(n)has length n (text or list)t.expect(body.items).toHaveLength(3)
.toHaveProperty(path)has a value at patht.expect(body).toHaveProperty("user.name")
.toHaveProperty(path, x)has x at patht.expect(body).toHaveProperty("user.name", "Ada")
.toMatch(x)is text that contains x, or matches the pattern xt.expect(body.email).toMatch(/@example\.com$/)
.toBeGreaterThan(n)is a number bigger than n
.toBeLessThan(n)is a number smaller than n

Put .not in front of any check to flip it:

js
t.expect(fluxify.response.body.password).not.toBeDefined();
t.expect(fluxify.response.status).not.toBe(500);

toBe or toEqual?

Use toBe for single values such as numbers and text. Use toEqual for objects and lists: two objects with the same content are "equal" but not the "same".

Checking the shape of data ​

t.zod is the zod library. Use it to check that data has the right shape, without listing every value:

js
const User = t.zod.object({
  id: t.zod.number(),
  email: t.zod.email(),
  tags: t.zod.array(t.zod.string()),
});

t.expect(User.safeParse(fluxify.response.body).success, "user shape").toBe(true);

The editor suggests names as you type fluxify., t. and t.zod..

Released under the Apache License 2.0. Enterprise features are under the Fluxify Enterprise Edition License.