Function ntex::web::test::read_body [−][src]
pub async fn read_body(res: WebResponse) -> Bytes
Expand description
Helper function that returns a response body of a WebResponse.
use bytes::Bytes; use ntex::http::header; use ntex::web::{self, test, App, HttpResponse}; #[ntex::test] async fn test_index() { let mut app = test::init_service( App::new().service( web::resource("/index.html") .route(web::post().to(|| async { HttpResponse::Ok().body("welcome!") }))) ).await; let req = test::TestRequest::post() .uri("/index.html") .header(header::CONTENT_TYPE, "application/json") .to_request(); let resp = test::call_service(&mut app, req).await; let result = test::read_body(resp); assert_eq!(result, Bytes::from_static(b"welcome!")); }