Skip to content

Commit

Permalink
fmt: wasm body (#1359)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Oct 18, 2021
1 parent d35c311 commit bd4e0c6
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/wasm/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use super::multipart::Form;
/// dox
use bytes::Bytes;
use js_sys::{Uint8Array};
use js_sys::Uint8Array;
use std::fmt;
use wasm_bindgen::JsValue;

Expand Down Expand Up @@ -131,7 +131,7 @@ impl fmt::Debug for Body {
#[cfg(test)]
mod tests {
// use js_sys::{Array, Uint8Array};
use wasm_bindgen::{prelude::*};
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;

wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
Expand All @@ -158,14 +158,21 @@ mod tests {

let body_value = "TEST";
let body = Body::from(body_value);

let mut init = web_sys::RequestInit::new();
init.method("POST");
init.body(Some(body.to_js_value().expect("could not convert body to JsValue").as_ref()));

let js_req = web_sys::Request::new_with_str_and_init("", &init).expect("could not create JS request");
init.body(Some(
body.to_js_value()
.expect("could not convert body to JsValue")
.as_ref(),
));

let js_req = web_sys::Request::new_with_str_and_init("", &init)
.expect("could not create JS request");
let text_promise = js_req.text().expect("could not get text promise");
let text = crate::wasm::promise::<JsValue>(text_promise).await.expect("could not get request body as text");
let text = crate::wasm::promise::<JsValue>(text_promise)
.await
.expect("could not get request body as text");

assert_eq!(text.as_string().expect("text is not a string"), body_value);
}
Expand Down

0 comments on commit bd4e0c6

Please sign in to comment.