},
}
};
html! {
render={switch} />
}
}
#[function_component(Root)]
fn root() -> Html {
html! {
}
}
// all the tests are in place because document state isn't being reset between tests
// different routes at the time of execution are set and it causes weird behavior (tests
// failing randomly)
// this test tests
// - routing
// - parameters in the path
// - query parameters
// - 404 redirects
#[test]
async fn router_works() {
yew::Renderer::::with_root(gloo::utils::document().get_element_by_id("output").unwrap())
.render();
sleep(Duration::ZERO).await;
assert_eq!("Home", obtain_result_by_id("result"));
sleep(Duration::ZERO).await;
let initial_length = history_length();
sleep(Duration::ZERO).await;
click("button"); // replacing the current route
sleep(Duration::ZERO).await;
assert_eq!("2", obtain_result_by_id("result-params"));
assert_eq!("bar", obtain_result_by_id("result-query"));
assert_eq!(initial_length, history_length());
click("button"); // pushing a new route
sleep(Duration::ZERO).await;
assert_eq!("3", obtain_result_by_id("result-params"));
assert_eq!("baz", obtain_result_by_id("result-query"));
assert_eq!(initial_length + 1, history_length());
}