dioxus/packages/core/tests/suspense.rs

43 lines
868 B
Rust
Raw Normal View History

2022-11-23 23:15:01 -08:00
use dioxus::prelude::*;
2023-07-14 17:13:49 -07:00
#[test]
fn it_works() {
2022-11-23 23:15:01 -08:00
// wait just a moment, not enough time for the boundary to resolve
2022-11-06 14:28:41 -08:00
tokio::runtime::Builder::new_current_thread()
.build()
.unwrap()
.block_on(async {
let mut dom = VirtualDom::new(app);
2024-01-11 12:40:36 -06:00
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
dom.wait_for_suspense().await;
2023-12-27 10:23:56 -06:00
let out = dioxus_ssr::render(&dom);
2023-01-09 13:50:33 -08:00
assert_eq!(out, "<div>Waiting for... child</div>");
2023-01-09 13:50:33 -08:00
dbg!(out);
});
2022-11-06 14:28:41 -08:00
}
fn app() -> Element {
2024-01-10 19:21:15 -06:00
render!(
2022-11-23 23:15:01 -08:00
div {
"Waiting for... "
suspended_child {}
2022-11-23 23:15:01 -08:00
}
2024-01-10 19:21:15 -06:00
)
2022-11-08 19:39:37 -08:00
}
2024-01-11 11:11:44 -06:00
fn suspended_child() -> Element {
let mut val = use_signal(|| 0);
2023-07-14 16:15:20 -07:00
2024-01-11 11:11:44 -06:00
if *val() < 3 {
2024-01-11 12:40:36 -06:00
spawn(async move {
val += 1;
});
2024-01-11 12:40:36 -06:00
suspend()?;
}
2023-07-14 16:15:20 -07:00
render!("child")
2022-11-06 14:28:41 -08:00
}