pub struct TestApp { /* private fields */ }Expand description
Headless test harness. Creates an App with TestBackend for automated testing.
TestApp does NOT run the full async event loop. Instead, events are processed
synchronously via process_event, allowing tests to control timing precisely.
§Example
use textual_rs::testing::TestApp;
let test_app = TestApp::new(80, 24, || Box::new(MyScreen));Implementations§
Source§impl TestApp
impl TestApp
Sourcepub fn new(
cols: u16,
rows: u16,
factory: impl FnOnce() -> Box<dyn Widget> + 'static,
) -> Self
pub fn new( cols: u16, rows: u16, factory: impl FnOnce() -> Box<dyn Widget> + 'static, ) -> Self
Create a new TestApp with the given root screen factory.
Initializes the reactive runtime (safe to call multiple times), mounts the root screen, and renders the initial frame.
Sourcepub fn new_styled(
cols: u16,
rows: u16,
css: &str,
factory: impl FnOnce() -> Box<dyn Widget> + 'static,
) -> Self
pub fn new_styled( cols: u16, rows: u16, css: &str, factory: impl FnOnce() -> Box<dyn Widget> + 'static, ) -> Self
Create a TestApp WITH built-in CSS (for tests that need proper widget layout).
Sourcepub fn ctx(&self) -> &AppContext
pub fn ctx(&self) -> &AppContext
Access the AppContext for state assertions (focus, widget ids, etc.).
Sourcepub fn backend(&self) -> &TestBackend
pub fn backend(&self) -> &TestBackend
Access the TestBackend directly (implements Display for insta snapshots).
Sourcepub fn inject_key_event(&mut self, key: KeyEvent)
pub fn inject_key_event(&mut self, key: KeyEvent)
Inject a key event without draining the message queue.
Used in tests that need to inspect the raw message queue immediately after key dispatch (e.g., to verify a specific message was posted before bubbling).
Sourcepub fn drain_messages(&self)
pub fn drain_messages(&self)
Drain the message queue explicitly (e.g., after inject_key_event).
Sourcepub fn process_event(&mut self, event: AppEvent)
pub fn process_event(&mut self, event: AppEvent)
Process a single event synchronously and re-render.
Used by Pilot to inject input. Can also be called directly for precise control.
Auto Trait Implementations§
impl !Freeze for TestApp
impl !RefUnwindSafe for TestApp
impl !Send for TestApp
impl !Sync for TestApp
impl Unpin for TestApp
impl UnsafeUnpin for TestApp
impl !UnwindSafe for TestApp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more