use dioxus::prelude::*;
#[test]
fn simple() {
fn App() -> Element {
render! { div { "hello!" } }
}
let mut dom = VirtualDom::new(App);
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(dioxus_ssr::render(&dom), "
hello!
");
assert_eq!(
dioxus_ssr::render_element(render!( div {"hello!"} )),
"hello!
"
);
}
#[test]
fn lists() {
assert_eq!(
dioxus_ssr::render_element(render! {
ul {
{
(0..5).map(|i| render! {
li { "item {i}" }
})
}
}
}),
"- item 0
- item 1
- item 2
- item 3
- item 4
"
);
}
#[test]
fn dynamic() {
let dynamic = 123;
assert_eq!(
dioxus_ssr::render_element(render! {
div { "Hello world 1 -->" "{dynamic}" "<-- Hello world 2" }
}),
"Hello world 1 -->123<-- Hello world 2
"
);
}
#[test]
fn components() {
#[derive(Props, Clone, PartialEq)]
struct MyComponentProps {
name: i32,
}
fn MyComponent(MyComponentProps { name }: MyComponentProps) -> Element {
render! { div { "component {name}" } }
}
assert_eq!(
dioxus_ssr::render_element(render! {
div {
{
(0..5).map(|name| render! {
MyComponent { name: name }
})
}
}
}),
"component 0
component 1
component 2
component 3
component 4
"
);
}
#[test]
fn fragments() {
assert_eq!(
dioxus_ssr::render_element(render! {
div {
{
(0..5).map(|_| render! ({}))
}
}
}),
""
);
}