Skip to main content

assert_json_response

Function assert_json_response 

Source
pub fn assert_json_response<T>(response: Response, expected: T)
Expand description

Assert that response contains expected JSON data (exact match)

This function deserializes the response body and compares it with the expected value. For subset matching, use assert_json_response_contains instead.

§Examples

use reinhardt_testkit::assertions::assert_json_response;
use reinhardt_http::Response;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct User {
    id: i64,
    name: String,
}

let user = User { id: 1, name: "Alice".to_string() };
let json = serde_json::to_vec(&user).unwrap();
let response = Response::ok()
    .with_header("Content-Type", "application/json")
    .with_body(json);

let expected = User { id: 1, name: "Alice".to_string() };
assert_json_response(response, expected);

§Panics

Panics if:

  • Response body is not valid JSON
  • Deserialized value doesn’t match expected