1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-22 17:41:11 +00:00

fix(docs): TestRequest example fixed (#2643)

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
Daze 2022-03-01 05:47:08 +05:45 committed by GitHub
parent 2f13e5f675
commit e7a05f9892
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,10 +24,10 @@ use crate::cookie::{Cookie, CookieJar};
/// ///
/// For unit testing, actix provides a request builder type and a simple handler runner. TestRequest implements a builder-like pattern. /// For unit testing, actix provides a request builder type and a simple handler runner. TestRequest implements a builder-like pattern.
/// You can generate various types of request via TestRequest's methods: /// You can generate various types of request via TestRequest's methods:
/// * `TestRequest::to_request` creates `actix_http::Request` instance. /// - [`TestRequest::to_request`] creates an [`actix_http::Request`](Request).
/// * `TestRequest::to_srv_request` creates `ServiceRequest` instance, which is used for testing middlewares and chain adapters. /// - [`TestRequest::to_srv_request`] creates a [`ServiceRequest`], which is used for testing middlewares and chain adapters.
/// * `TestRequest::to_srv_response` creates `ServiceResponse` instance. /// - [`TestRequest::to_srv_response`] creates a [`ServiceResponse`].
/// * `TestRequest::to_http_request` creates `HttpRequest` instance, which is used for testing handlers. /// - [`TestRequest::to_http_request`] creates an [`HttpRequest`], which is used for testing handlers.
/// ///
/// ``` /// ```
/// use actix_web::{test, HttpRequest, HttpResponse, HttpMessage}; /// use actix_web::{test, HttpRequest, HttpResponse, HttpMessage};
@ -42,15 +42,17 @@ use crate::cookie::{Cookie, CookieJar};
/// } /// }
/// ///
/// #[actix_web::test] /// #[actix_web::test]
/// # // force rustdoc to display the correct thing and also compile check the test
/// # async fn _test() {}
/// async fn test_index() { /// async fn test_index() {
/// let req = test::TestRequest::default().insert_header("content-type", "text/plain") /// let req = test::TestRequest::default().insert_header(header::ContentType::plaintext())
/// .to_http_request(); /// .to_http_request();
/// ///
/// let resp = index(req).await.unwrap(); /// let resp = index(req).await;
/// assert_eq!(resp.status(), StatusCode::OK); /// assert_eq!(resp.status(), StatusCode::OK);
/// ///
/// let req = test::TestRequest::default().to_http_request(); /// let req = test::TestRequest::default().to_http_request();
/// let resp = index(req).await.unwrap(); /// let resp = index(req).await;
/// assert_eq!(resp.status(), StatusCode::BAD_REQUEST); /// assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
/// } /// }
/// ``` /// ```