assert Action
Used in FLAT tests to assert expected results.
Syntax
The body is a JSON array of assertions. An assertion is an array itself, with up to three values:
Expression: as string (see
eval
); (required)Expected result: a literal value (string, number, boolean, or
null
) or an object with compare flags (see below); (optional, default:true
)Message: String literal to be included in output of failed tests; (optional)
Note that the expression must be a string. You can use template syntax, but the resulting array of assertions must still contain a string as the expression parameter.
Examples
Compare Flags
The expected value (second value) can be an object that defines one or more compare flags:
file
: read wanted text from a golden filemode
: eithertext
orjson
.json
mode validates JSON syntax in both expected and actual result; compares JSON in compact (un-pretty) formatting.contains
: a string that must be contained in the expression resultpattern
: a regular expression pattern (with delimiters and optional modifiers) that the expression result must match.
The Testing Templates recipe provides a full example.
See also
Testing Templates (cookbook)
Testing Upstream Requests (cookbook)
Testing (reference)
Last updated