diff --git a/crates/hooks/src/use_animation.rs b/crates/hooks/src/use_animation.rs index b6ab36135..ab5561b85 100644 --- a/crates/hooks/src/use_animation.rs +++ b/crates/hooks/src/use_animation.rs @@ -155,7 +155,7 @@ mod test { assert_eq!(utils.root().get(0).layout().unwrap().width(), 0.0); // State somewhere in the middle - sleep(Duration::from_millis(32)).await; + sleep(Duration::from_millis(15)).await; utils.wait_for_update().await; let width = utils.root().get(0).layout().unwrap().width(); diff --git a/crates/hooks/src/use_animation_transition.rs b/crates/hooks/src/use_animation_transition.rs index 1164dd0c9..67833db26 100644 --- a/crates/hooks/src/use_animation_transition.rs +++ b/crates/hooks/src/use_animation_transition.rs @@ -348,7 +348,7 @@ mod test { assert_eq!(utils.root().get(0).layout().unwrap().width(), 0.0); // State somewhere in the middle - sleep(Duration::from_millis(32)).await; + sleep(Duration::from_millis(15)).await; utils.wait_for_update().await; let width = utils.root().get(0).layout().unwrap().width(); diff --git a/crates/testing/src/test_handler.rs b/crates/testing/src/test_handler.rs index 98dc5561d..085250f94 100644 --- a/crates/testing/src/test_handler.rs +++ b/crates/testing/src/test_handler.rs @@ -12,7 +12,7 @@ use torin::geometry::{Area, Size2D}; pub use freya_core::events::FreyaEvent; pub use freya_elements::events::mouse::MouseButton; -use tokio::time::{sleep, timeout}; +use tokio::time::{interval, timeout}; use crate::test_node::TestNode; use crate::test_utils::TestUtils; @@ -71,7 +71,11 @@ impl TestingHandler { self.provide_vdom_contexts(); - let vdom = &mut self.vdom; + let mut ticker = if self.config.run_ticker { + Some(interval(Duration::from_millis(16))) + } else { + None + }; // Handle platform and VDOM events loop { @@ -85,9 +89,12 @@ impl TestingHandler { if let Ok(ev) = platform_ev { match ev { EventMessage::RequestRerender => { - if self.config.run_ticker { - sleep(Duration::from_millis(16)).await; + if let Some(ticker) = ticker.as_mut() { + ticker.tick().await; self.ticker_sender.send(()).unwrap(); + timeout(self.config.vdom_timeout(), self.vdom.wait_for_work()) + .await + .ok(); } } EventMessage::FocusAccessibilityNode(node_id) => { @@ -101,12 +108,13 @@ impl TestingHandler { } if let Ok(ev) = vdom_ev { - vdom.handle_event(&ev.name, ev.data.any(), ev.element_id, false); - vdom.process_events(); + self.vdom + .handle_event(&ev.name, ev.data.any(), ev.element_id, false); + self.vdom.process_events(); } } - timeout(self.config.vdom_timeout(), vdom.wait_for_work()) + timeout(self.config.vdom_timeout(), self.vdom.wait_for_work()) .await .ok();