Skip to main content

assert_json_response_contains

Function assert_json_response_contains 

Source
pub fn assert_json_response_contains(
    response: &Response,
    expected_key: &str,
    expected_value: &Value,
)
Expand description

Assert that response is JSON and contains expected field with value

§Examples

use reinhardt_testkit::assertions::assert_json_response_contains;
use reinhardt_http::Response;
use serde_json::json;

let json = json!({"name": "Alice", "age": 30, "city": "NYC"});
let response = Response::ok()
    .with_header("Content-Type", "application/json")
    .with_body(serde_json::to_vec(&json).unwrap());

assert_json_response_contains(&response, "name", &json!("Alice"));

§Panics

Panics if:

  • Response body is not valid JSON
  • JSON doesn’t contain the expected field
  • Field value doesn’t match expected