[−][src]Function actix_web::test::read_response
pub async fn read_response<'_, S, B>(app: &'_ mut S, req: Request) -> Bytes where
S: Service<Request = Request, Response = ServiceResponse<B>, Error = Error>,
B: MessageBody,
Helper function that returns a response body of a TestRequest
use actix_web::{test, web, App, HttpResponse, http::header}; use bytes::Bytes; #[actix_rt::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 result = test::read_response(&mut app, req).await; assert_eq!(result, Bytes::from_static(b"welcome!")); }