From b8eeb06ec4a935378bd56ecc0ac798737d2b0b2e Mon Sep 17 00:00:00 2001 From: Mattias Buelens Date: Tue, 31 Oct 2023 19:34:05 +0100 Subject: [PATCH] Add test --- tests/tests/readable_stream.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/tests/readable_stream.rs b/tests/tests/readable_stream.rs index c353178..30311b2 100644 --- a/tests/tests/readable_stream.rs +++ b/tests/tests/readable_stream.rs @@ -298,3 +298,17 @@ async fn test_readable_stream_into_stream_then_into_async_read() { assert_eq!(async_read.read(&mut buf).await.unwrap(), 0); assert_eq!(&buf, &[4, 5, 6]); } + +#[wasm_bindgen_test] +async fn test_readable_stream_from_js_array() { + let js_array = + js_sys::Array::from_iter([JsValue::from_str("Hello"), JsValue::from_str("world!")]); + let mut readable = ReadableStream::from(js_array.unchecked_into()); + assert!(!readable.is_locked()); + + let mut reader = readable.get_reader(); + assert_eq!(reader.read().await.unwrap(), Some(JsValue::from("Hello"))); + assert_eq!(reader.read().await.unwrap(), Some(JsValue::from("world!"))); + assert_eq!(reader.read().await.unwrap(), None); + reader.closed().await.unwrap(); +}