use std::time::Duration; use yew::platform::time::sleep; use yew::prelude::*; use yew_router::prelude::*; mod utils; use utils::*; use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; wasm_bindgen_test_configure!(run_in_browser); #[derive(Routable, Debug, Clone, PartialEq)] enum AppRoute { #[at("/")] Root, #[at("/search/:query")] Search { query: String }, } #[function_component] fn Comp() -> Html { let switch = move |routes: AppRoute| match routes { AppRoute::Root => html! { <>

{ "Root" }

to={AppRoute::Search { query: "a/b".to_string() }}> {"Click me"} > }, AppRoute::Search { query } => html! {

{ query }

}, }; html! { render={switch} /> } } #[function_component(Root)] fn root() -> Html { html! { } } #[test] async fn url_encoded_roundtrip() { yew::Renderer::::with_root(gloo::utils::document().get_element_by_id("output").unwrap()) .render(); sleep(Duration::ZERO).await; click("a"); sleep(Duration::ZERO).await; let res = obtain_result_by_id("q"); assert_eq!(res, "a/b"); assert_eq!( gloo::utils::window().location().pathname().unwrap(), "/search/a%2Fb" ) }