Skip to content

Commit 159387a

Browse files
committed
avoid string then json in tests, parse as json directly
1 parent f8ec60f commit 159387a

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

tests/data_formats/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ async fn test_json_body() -> actix_web::Result<()> {
3131
resp.headers().get(header::CONTENT_TYPE).unwrap(),
3232
"application/json"
3333
);
34-
let body = test::read_body(resp).await;
35-
let body_json: serde_json::Value = serde_json::from_slice(&body).unwrap();
34+
let body_json: serde_json::Value = test::read_body_json(resp).await;
3635
assert_eq!(
3736
body_json,
3837
serde_json::json!([{"message": "It works!"}, {"cool": "cool"}])
@@ -106,8 +105,7 @@ async fn test_accept_json_returns_json_array() -> actix_web::Result<()> {
106105
resp.headers().get(header::CONTENT_TYPE).unwrap(),
107106
"application/json"
108107
);
109-
let body = test::read_body(resp).await;
110-
let body_json: serde_json::Value = serde_json::from_slice(&body).unwrap();
108+
let body_json: serde_json::Value = test::read_body_json(resp).await;
111109
assert!(body_json.is_array());
112110
let arr = body_json.as_array().unwrap();
113111
assert!(arr.len() >= 2);

0 commit comments

Comments
 (0)