Skip to main content

revue/testing/pilot/
async_pilot.rs

1use super::core::Pilot;
2
3/// Async test runner for Pilot
4///
5/// Provides a more ergonomic way to run async tests.
6///
7/// # Example
8///
9/// ```rust,ignore
10/// use revue::testing::*;
11///
12/// #[tokio::test]
13/// async fn test_async_pilot() {
14///     let view = MyView::new();
15///     let mut app = TestApp::new(view);
16///     let pilot = Pilot::new(&mut app);
17///
18///     pilot.type_text("hello");
19///     pilot.wait_ms_async(100).await;
20///     pilot.assert_contains("hello");
21/// }
22/// ```
23pub struct AsyncPilot;
24
25impl AsyncPilot {
26    /// Create a test runner that will run the test asynchronously
27    #[cfg(feature = "async")]
28    pub async fn run<V, F, Fut>(view: V, f: F)
29    where
30        V: crate::widget::View,
31        F: FnOnce(Pilot<'_, V>) -> Fut,
32        Fut: std::future::Future<Output = ()>,
33    {
34        let mut app = crate::testing::TestApp::new(view);
35        let pilot = Pilot::new(&mut app);
36        f(pilot).await;
37    }
38}