pub async fn call_service_res<S, R, B, E>(
app: &mut S,
req: R,
) -> Result<S::Response, S::Error>Expand description
Calls service and waits for response future completion.
ยงNote
When testing baerer/basic login which ends with AuthentificationError original method panic.
This method returns Result<T> not T with unwrap
use actix_web::{test, App, HttpResponse, http::StatusCode};
use actix_service::Service;
#[test]
fn test_response() {
let mut app = test::init_service(
App::new()
.service(web::resource("/test").to(|| async {
HttpResponse::Ok()
}))
).await;
// Create request object
let req = test::TestRequest::with_uri("/test").to_request();
// Call application
let resp = test::call_service(&mut app, req).await;
assert!(resp.is_ok());
assert_eq!(resp.unwrap().status(), StatusCode::OK);
}