assert Action #

Used in FLAT tests to assert expected results.

Syntax #

<assert>
[
  [ "$status", 200, "status is 200" ]
]
</assert>

The body is a JSON array of assertions. An assertion is an array itself, with up to three values:

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 #

<assert>
[
  [ "$foo", "bar", "…" ],
  [ "$request/headers/authorization", null, "No Authorization header is set" ],
  [ "$response", "OK" ],
  [ "json-parse($response)/user", "alice" ],
  [ "$status", 201, "got 201 - created" ],
  [ "true()", true, "for sure!" ]
]
</assert>

Compare Flags #

The expected value (second value) can be an object that defines one or more compare flags:

<assert>
[
  [ "$response", {"file": "login.golden", "mode": "json"} ]
]
</assert>

<assert>
[
  [ "$s1", {"contains": "foo bar"} ],
  [ "$s2", {"pattern": "#^[a-z ]+$#i"} ]
]
</assert>

The Testing Templates recipe provides a full example.

See also #