dioxus/packages/web/tests/hydrate.rs

57 lines
1.2 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() -> Element {
2024-01-14 05:12:21 +00:00
rsx! {
2022-01-07 05:33:09 +00:00
div {
2024-01-16 18:28:21 +00:00
div { h1 {} }
div { h2 {} }
2022-01-07 05:33:09 +00:00
}
2024-01-16 18:28:21 +00:00
}
2022-01-07 05:33:09 +00:00
}
let mut dom = VirtualDom::new(app);
2024-01-16 18:28:21 +00:00
let muts = dom.rebuild_to_vec();
2022-01-07 05:33:09 +00:00
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() -> Element {
2024-01-14 05:12:21 +00:00
rsx! {
2022-01-07 05:33:09 +00:00
div {
2024-01-16 18:28:21 +00:00
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
}
2024-01-16 18:28:21 +00:00
}
2022-01-07 05:33:09 +00:00
}
let mut dom = VirtualDom::new(app);
2024-01-10 23:57:15 +00:00
let _ = dom.rebuild(&mut dioxus_core::NoOpMutations);
let out = dioxus_ssr::render(&dom);
window()
.unwrap()
.document()
.unwrap()
.body()
.unwrap()
2023-01-28 02:35:46 +00:00
.set_inner_html(&format!("<div id='main'>{out}</div>"));
dioxus_web::launch::launch_cfg(app, Config::new().hydrate(true));
2022-01-07 05:33:09 +00:00
}