2022-11-24 07:15:01 +00:00
|
|
|
use dioxus::prelude::*;
|
2023-07-15 00:13:49 +00:00
|
|
|
|
2023-07-15 00:12:07 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn it_works() {
|
2022-11-24 07:15:01 +00:00
|
|
|
// wait just a moment, not enough time for the boundary to resolve
|
2022-11-06 22:28:41 +00:00
|
|
|
|
2023-07-15 00:12:07 +00:00
|
|
|
let mut dom = VirtualDom::new(app);
|
|
|
|
_ = dom.rebuild();
|
|
|
|
dom.wait_for_suspense().await;
|
|
|
|
let out = dioxus_ssr::pre_render(&dom);
|
2023-01-09 21:50:33 +00:00
|
|
|
|
2023-07-15 00:12:07 +00:00
|
|
|
assert_eq!(out, "<div>Waiting for... child</div>");
|
2023-01-09 21:50:33 +00:00
|
|
|
|
2023-07-15 00:12:07 +00:00
|
|
|
dbg!(out);
|
2022-11-06 22:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn app(cx: Scope) -> Element {
|
2022-11-24 07:15:01 +00:00
|
|
|
cx.render(rsx!(
|
|
|
|
div {
|
2023-07-15 00:12:07 +00:00
|
|
|
"Waiting for... "
|
|
|
|
suspended_child {}
|
2022-11-24 07:15:01 +00:00
|
|
|
}
|
|
|
|
))
|
2022-11-09 03:39:37 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 00:12:07 +00:00
|
|
|
fn suspended_child(cx: Scope) -> Element {
|
2023-07-15 00:13:49 +00:00
|
|
|
let val = use_state(cx, || 0);
|
2023-07-14 23:15:20 +00:00
|
|
|
|
2023-07-15 00:12:07 +00:00
|
|
|
if **val < 3 {
|
|
|
|
let mut val = val.clone();
|
|
|
|
cx.spawn(async move {
|
|
|
|
val += 1;
|
|
|
|
});
|
|
|
|
return cx.suspend()?;
|
|
|
|
}
|
2023-07-14 23:15:20 +00:00
|
|
|
|
2023-07-15 00:12:07 +00:00
|
|
|
render!("child")
|
2022-11-06 22:28:41 +00:00
|
|
|
}
|