use dioxus::prelude::*; #[test] fn root_ids() { fn app(cx: Scope) -> Element { render! { div { width: "100px" } } } let mut dom = VirtualDom::new(app); _ = dom.rebuild(); assert_eq!( dioxus_ssr::pre_render(&dom), r#"
"# ); } #[test] fn dynamic_attributes() { fn app(cx: Scope) -> Element { let dynamic = 123; render! { div { width: "100px", div { width: "{dynamic}px" } } } } let mut dom = VirtualDom::new(app); _ = dom.rebuild(); assert_eq!( dioxus_ssr::pre_render(&dom), r#"
"# ); } #[test] fn listeners() { fn app(cx: Scope) -> Element { render! { div { width: "100px", div { onclick: |_| {} } } } } let mut dom = VirtualDom::new(app); _ = dom.rebuild(); assert_eq!( dioxus_ssr::pre_render(&dom), r#"
"# ); fn app2(cx: Scope) -> Element { let dynamic = 123; render! { div { width: "100px", div { width: "{dynamic}px", onclick: |_| {} } } } } let mut dom = VirtualDom::new(app2); _ = dom.rebuild(); assert_eq!( dioxus_ssr::pre_render(&dom), r#"
"# ); } #[test] fn text_nodes() { fn app(cx: Scope) -> Element { let dynamic_text = "hello"; render! { div { dynamic_text } } } let mut dom = VirtualDom::new(app); _ = dom.rebuild(); assert_eq!( dioxus_ssr::pre_render(&dom), r#"
hello
"# ); fn app2(cx: Scope) -> Element { let dynamic = 123; render! { div { "{dynamic}", "{1234}" } } } let mut dom = VirtualDom::new(app2); _ = dom.rebuild(); assert_eq!( dioxus_ssr::pre_render(&dom), r#"
1231234
"# ); } #[test] fn hello_world_hydrates() { fn app(cx: Scope) -> Element { let mut count = use_state(cx, || 0); cx.render(rsx! { h1 { "High-Five counter: {count}" } button { onclick: move |_| count += 1, "Up high!" } button { onclick: move |_| count -= 1, "Down low!" } }) } let mut dom = VirtualDom::new(app); _ = dbg!(dom.rebuild()); assert_eq!( dioxus_ssr::pre_render(&dom), r#"

High-Five counter: 0

"# ); }