expect.* builds an assertion record and s.expect.* builds a statement. They are not
interchangeable, and the types enforce it.
A unit test
Each entry is a named set of inputs run against that object:mock keyed by test name, which returns a value instead of doing its
work while that one test runs:
On a tool, prompt or resource
tool(), prompt() and resource() take tests the same way. The test’s input is the
tool’s input, the prompt’s arguments or the resource’s URI variables:
tool:<name>/<test> (prompt: and resource: for
the others). A pull brings them back with their mocks, so a deploy from a pulled tree keeps tests
written in the Xano editor.
A backend on an engine older than tests on these kinds lists none of them, so the suite passes
without running them. Check
npx @xano/sdk test list when a tool’s tests seem to be missing.A workflow test
A workflow test calls other objects and asserts on what they bind:.registerFunctions([addNote]) and .registerWorkflowTests([addNoteWorks]).
A workflow test can run another with s.workflow_test.call, and export() fails with
reference.unresolved when the one it calls is not registered.
s.expect.*takes one argument object, with the subject asexpr:{ expr }for a subject-only assertion such asto_be_defined,{ expr, value }for one with an operand such asto_equal,{ expr, min, max }forto_be_within, and{ body, exception? }forto_throw, wherebodyis the statements expected to fail.- Four calls run only here.
s.api.call,s.task.call,s.trigger.callands.workflow_test.callwork only in aworkflowTest()stack. In a query, function or task the engine cannot reach the target, soexport()refuses them there.s.function.callruns from any stack. - A failing call does not always raise.
s.api.callbinds a stack error’s{ code, message, payload }toasand the test carries on, so assert onref("r.code")when a call may fail.
Run them
Tests run against what is deployed, so deploy first:test runs on the backend this project last deployed to. --on names another:
--on workspace runs against your real database. That is safe only while every test keeps the
default empty datasource.
Deploy and test in one step
--test runs the suite after a deploy, against what it just shipped. This is the first step of
the release flow:
--json (or a stdout that is not a terminal) prints one JSON document naming each test and its
status, so CI can report which test failed. See CI/CD and
exit codes.
Next
- Every assertion, mocks, and what
s.api.callcan and cannot do in a workflow test:node_modules/@xano/sdk/llms/tests.md, the one in-package file for tests, and the object kinds reference. - Keep secrets out of the repo: Environment variables and secrets.
- Ship what passed: Releases.