mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-15 00:47:09 +00:00
43 lines
923 B
Rust
43 lines
923 B
Rust
use dioxus::prelude::*;
|
|
|
|
#[test]
|
|
fn it_works() {
|
|
// wait just a moment, not enough time for the boundary to resolve
|
|
|
|
tokio::runtime::Builder::new_current_thread()
|
|
.build()
|
|
.unwrap()
|
|
.block_on(async {
|
|
let mut dom = VirtualDom::new(app);
|
|
_ = dom.rebuild_to_vec(&mut dioxus_core::NoOpMutations);
|
|
dom.wait_for_suspense().await;
|
|
let out = dioxus_ssr::render(&dom);
|
|
|
|
assert_eq!(out, "<div>Waiting for... child</div>");
|
|
|
|
dbg!(out);
|
|
});
|
|
}
|
|
|
|
fn app() -> Element {
|
|
render!(
|
|
div {
|
|
"Waiting for... "
|
|
suspended_child {}
|
|
}
|
|
)
|
|
}
|
|
|
|
fn suspended_child(cx: Scope) -> Element {
|
|
let val = use_state(cx, || 0);
|
|
|
|
if **val < 3 {
|
|
let mut val = val.clone();
|
|
cx.spawn(async move {
|
|
val += 1;
|
|
});
|
|
cx.suspend()?;
|
|
}
|
|
|
|
render!("child")
|
|
}
|