Expand description
§Tide Testing Extension Trait
This trait provides an ergonomic extension for testing tide applications.
§Usage:
$ cargo add -D tide-testing
§Examples
let mut app = tide::new();
app.at("/").get(|_| async { Ok("hello!") });
use tide_testing::TideTestingExt;
assert_eq!(app.get("/").recv_string().await?, "hello!");
assert_eq!(
app.post("/missing").await?.status(),
tide::http::StatusCode::NotFound
);
Note that the http methods return surf::RequestBuilder
s, allowing tests to build up complex requests fluently:
use tide::prelude::*;
let mut app = tide::new();
app.at("/complex_example")
.put(|mut request: tide::Request<()>| async move {
Ok(json!({
"content_type": request.content_type().map(|c| c.to_string()),
"body": request.body_string().await?,
"header": request.header("custom").map(|h| h.as_str())
}))
});
use tide_testing::TideTestingExt;
let response_body: serde_json::value::Value = app
.put("/complex_example")
.body(tide::Body::from_string("hello".into()))
.content_type("application/custom")
.header("custom", "header-value")
.recv_json()
.await?;
assert_eq!(
response_body,
json!({
"content_type": Some("application/custom"),
"body": "hello",
"header": Some("header-value")
})
);
Re-exports§
pub use surf;