Add unit test for getting bytes from message
@@ -51,7 +51,7 @@ impl WebSocketMessage {
let blob = gloo_file::Blob::from(blob.to_owned());
let bytes = gloo_file::futures::read_as_bytes(&blob)
.await
- .map_err(WebSocketError::FileRedaerError)?;
+ .map_err(WebSocketError::FileReaderError)?;
return Ok(bytes);
}
@@ -112,3 +112,23 @@ impl WebSocketMessage {
&self.message_event
}
}
+
+#[cfg(test)]
+pub mod tests {
+ use crate::browser::web_socket::WebSocketMessage;
+ use wasm_bindgen_test::*;
+ wasm_bindgen_test_configure!(run_in_browser);
+
+ #[wasm_bindgen_test]
+ async fn get_bytes_from_message() {
+ let bytes = "some test message".as_bytes();
+ let blob = gloo_file::Blob::new(bytes);
+ let message_event = web_sys::MessageEvent::new("test").unwrap();
+ let ws_msg = WebSocketMessage {
+ data: blob.into(),
+ message_event,
+ };
+ let result_bytes = ws_msg.bytes().await.unwrap();
+ assert_eq!(bytes, &*result_bytes);
+ }
+}
