dioxus/packages/web/tests/hydrate.rs

65 lines
1.4 KiB
Rust
Raw Normal View History

2022-06-25 13:27:10 +00:00
use dioxus::prelude::*;
use dioxus_web::Config;
2022-01-07 05:33:09 +00:00
use wasm_bindgen_test::wasm_bindgen_test;
use web_sys::window;
2022-01-07 05:33:09 +00:00
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
#[test]
fn makes_tree() {
fn app(cx: Scope) -> Element {
cx.render(rsx! {
div {
div {
h1 {}
}
div {
h2 {}
}
2022-01-07 05:33:09 +00:00
}
})
}
let mut dom = VirtualDom::new(app);
let muts = dom.rebuild();
2022-12-01 05:46:15 +00:00
dbg!(muts.edits);
2022-01-07 05:33:09 +00:00
}
#[wasm_bindgen_test]
fn rehydrates() {
fn app(cx: Scope) -> Element {
cx.render(rsx! {
div {
div {
h1 { "h1" }
}
div {
h2 { "h2" }
}
button {
onclick: move |_| {
println!("clicked");
},
"listener test"
}
false.then(|| rsx!{ "hello" })
2022-01-07 05:33:09 +00:00
}
})
}
let mut dom = VirtualDom::new(app);
let _ = dom.rebuild();
2022-11-30 22:21:10 +00:00
let out = dioxus_ssr::render_vdom_cfg(&dom, Default::default());
window()
.unwrap()
.document()
.unwrap()
.body()
.unwrap()
.set_inner_html(&format!("<div id='main'>{}</div>", out));
dioxus_web::launch_cfg(app, Config::new().hydrate(true));
2022-01-07 05:33:09 +00:00
}