Skip to main content

TestApp

Struct TestApp 

Source
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

Source

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.

Source

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).

Source

pub fn pilot(&mut self) -> Pilot<'_>

Get a Pilot for sending simulated input events.

Source

pub fn ctx(&self) -> &AppContext

Access the AppContext for state assertions (focus, widget ids, etc.).

Source

pub fn buffer(&self) -> &Buffer

Access the rendered buffer for row-level assertions.

Source

pub fn backend(&self) -> &TestBackend

Access the TestBackend directly (implements Display for insta snapshots).

Source

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).

Source

pub fn drain_messages(&self)

Drain the message queue explicitly (e.g., after inject_key_event).

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.