11use std:: time:: Duration ;
22
3- use gloo:: console:: console_dbg;
43use serde:: { Deserialize , Serialize } ;
54use wasm_bindgen_test:: { wasm_bindgen_test as test, wasm_bindgen_test_configure} ;
65use yew:: functional:: function_component;
@@ -94,7 +93,7 @@ async fn link_in_browser_router() {
9493 let div = gloo:: utils:: document ( ) . create_element ( "div" ) . unwrap ( ) ;
9594 let _ = div. set_attribute ( "id" , "browser-router" ) ;
9695 let _ = gloo:: utils:: body ( ) . append_child ( & div) ;
97- yew:: Renderer :: < RootForBrowserRouter > :: with_root ( div) . render ( ) ;
96+ let handle = yew:: Renderer :: < RootForBrowserRouter > :: with_root ( div) . render ( ) ;
9897
9998 sleep ( Duration :: ZERO ) . await ;
10099
@@ -113,6 +112,8 @@ async fn link_in_browser_router() {
113112 "/search?q=Rust&lang=en_US" ,
114113 link_href( "#browser-router ul > li.search-q-lang > a" )
115114 ) ;
115+
116+ handle. destroy ( ) ;
116117}
117118
118119#[ derive( PartialEq , Properties ) ]
@@ -122,7 +123,6 @@ struct BasenameProps {
122123
123124#[ function_component( RootForBasename ) ]
124125fn root_for_basename ( props : & BasenameProps ) -> Html {
125- console_dbg ! ( "outer render" ) ;
126126 html ! {
127127 <BrowserRouter basename={ props. basename. clone( ) } >
128128 <NavigationMenu />
@@ -142,16 +142,12 @@ async fn link_with_basename() {
142142 )
143143 . render ( ) ;
144144
145- for _ in 0 ..10 {
146- sleep ( Duration :: from_millis ( 100 ) ) . await ;
147- }
145+ sleep ( Duration :: ZERO ) . await ;
148146
149- /*
150147 assert_eq ! (
151148 "/base/" ,
152149 gloo:: utils:: window( ) . location( ) . pathname( ) . unwrap( )
153150 ) ;
154- */
155151
156152 assert_eq ! ( "/base/posts" , link_href( "#with-basename ul > li.posts > a" ) ) ;
157153 assert_eq ! (
@@ -177,18 +173,12 @@ async fn link_with_basename() {
177173 basename : Some ( "/bayes/" . to_owned ( ) ) ,
178174 } ) ;
179175
180- for _ in 0 ..10 {
181- sleep ( Duration :: from_millis ( 100 ) ) . await ;
182- }
183-
184- console_dbg ! ( "before assert" ) ;
176+ sleep ( Duration :: ZERO ) . await ;
185177
186- /*
187178 assert_eq ! (
188179 "/bayes/" ,
189180 gloo:: utils:: window( ) . location( ) . pathname( ) . unwrap( )
190181 ) ;
191- */
192182
193183 assert_eq ! (
194184 "/bayes/posts" ,
@@ -198,29 +188,27 @@ async fn link_with_basename() {
198188 // Some -> None
199189 handle. update ( BasenameProps { basename : None } ) ;
200190
201- for _ in 0 ..10 {
202- sleep ( Duration :: from_millis ( 100 ) ) . await ;
203- }
191+ sleep ( Duration :: ZERO ) . await ;
204192
205193 assert_eq ! ( "/" , gloo:: utils:: window( ) . location( ) . pathname( ) . unwrap( ) ) ;
206194
207195 assert_eq ! ( "/posts" , link_href( "#with-basename ul > li.posts > a" ) ) ;
208196
209197 // None -> Some
210198 handle. update ( BasenameProps {
211- basename : Some ( "bass" . to_string ( ) ) ,
199+ basename : Some ( "/ bass/ " . to_string ( ) ) ,
212200 } ) ;
213201
214- for _ in 0 ..10 {
215- sleep ( Duration :: from_millis ( 100 ) ) . await ;
216- }
202+ sleep ( Duration :: ZERO ) . await ;
217203
218204 assert_eq ! (
219205 "/bass/" ,
220206 gloo:: utils:: window( ) . location( ) . pathname( ) . unwrap( )
221207 ) ;
222208
223209 assert_eq ! ( "/bass/posts" , link_href( "#with-basename ul > li.posts > a" ) ) ;
210+
211+ handle. destroy ( ) ;
224212}
225213
226214#[ function_component( RootForHashRouter ) ]
@@ -236,7 +224,7 @@ async fn link_in_hash_router() {
236224 let div = gloo:: utils:: document ( ) . create_element ( "div" ) . unwrap ( ) ;
237225 let _ = div. set_attribute ( "id" , "hash-router" ) ;
238226 let _ = gloo:: utils:: body ( ) . append_child ( & div) ;
239- yew:: Renderer :: < RootForHashRouter > :: with_root ( div) . render ( ) ;
227+ let handle = yew:: Renderer :: < RootForHashRouter > :: with_root ( div) . render ( ) ;
240228
241229 sleep ( Duration :: ZERO ) . await ;
242230
@@ -255,6 +243,8 @@ async fn link_in_hash_router() {
255243 "#/search?q=Rust&lang=en_US" ,
256244 link_href( "#hash-router ul > li.search-q-lang > a" )
257245 ) ;
246+
247+ handle. destroy ( ) ;
258248}
259249
260250// These cannot be run in concurrently because they all read/write the URL.
0 commit comments