use std::time::Duration; use anymap2::AnyMap; use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; wasm_bindgen_test_configure!(run_in_browser); use bounce::prelude::*; use bounce::BounceRoot; use gloo::timers::future::sleep; use gloo::utils::document; use yew::prelude::*; async fn get_text_content>(selector: S) -> String { sleep(Duration::ZERO).await; document() .query_selector(selector.as_ref()) .unwrap() .unwrap() .text_content() .unwrap() } #[derive(Atom, PartialEq, Default)] struct State { inner: u32, } #[function_component(Comp)] fn comp() -> Html { let a = use_atom_value::(); html! {
{a.inner}
} } #[test] async fn test_without_init_states() { #[function_component(Root)] fn root() -> Html { html! { } } yew::Renderer::::with_root(document().query_selector("#output").unwrap().unwrap()) .render(); let s = get_text_content("#a").await; assert_eq!(s, "0"); } #[test] async fn test_with_init_states() { #[function_component(Root)] fn root() -> Html { fn get_init_states(_: ()) -> AnyMap { let mut map = AnyMap::new(); map.insert(State { inner: 1 }); map } html! { } } yew::Renderer::::with_root(document().query_selector("#output").unwrap().unwrap()) .render(); let s = get_text_content("#a").await; assert_eq!(s, "1"); }