pub struct TestRunner<A: App> { /* private fields */ }Expand description
A test runner for TEA applications
Provides a convenient way to test update logic without running the UI.
Implementations§
Source§impl<A: App> TestRunner<A>
impl<A: App> TestRunner<A>
Sourcepub fn with_model(model: A::Model) -> Self
pub fn with_model(model: A::Model) -> Self
Create a test runner with a custom initial model
Sourcepub fn send_all(&mut self, msgs: impl IntoIterator<Item = A::Msg>) -> &mut Self
pub fn send_all(&mut self, msgs: impl IntoIterator<Item = A::Msg>) -> &mut Self
Send multiple messages in sequence
Sourcepub fn clear_commands(&mut self) -> &mut Self
pub fn clear_commands(&mut self) -> &mut Self
Clear command history
Sourcepub fn last_was_none(&self) -> bool
pub fn last_was_none(&self) -> bool
Check if the last command was Cmd::None
Sourcepub fn last_was_task(&self) -> bool
pub fn last_was_task(&self) -> bool
Check if the last command was Cmd::Task
Sourcepub fn last_was_msg(&self) -> bool
pub fn last_was_msg(&self) -> bool
Check if the last command was Cmd::Msg
Sourcepub fn pending_task_count(&self) -> usize
pub fn pending_task_count(&self) -> usize
Get the number of pending async tasks
Sourcepub fn has_pending_tasks(&self) -> bool
pub fn has_pending_tasks(&self) -> bool
Check if there are any pending async tasks
Sourcepub async fn process_task(&mut self) -> bool
pub async fn process_task(&mut self) -> bool
Process one pending async task
Executes the first pending task, awaits its result, and sends the resulting message through update.
Returns true if a task was processed, false if no tasks were pending.
§Example
runner.send(Msg::FetchData);
assert!(runner.has_pending_tasks());
runner.process_task().await;
assert!(!runner.has_pending_tasks());Sourcepub async fn process_tasks(&mut self) -> &mut Self
pub async fn process_tasks(&mut self) -> &mut Self
Process all pending async tasks
Processes tasks until none remain. Note that processing a task may add new tasks (if the resulting message produces new Cmd::Task), so this processes until the queue is fully drained.
§Example
runner.send(Msg::FetchData);
runner.process_tasks().await;
// All tasks completed, results sent through updateSourcepub async fn process_n_tasks(&mut self, n: usize) -> &mut Self
pub async fn process_n_tasks(&mut self, n: usize) -> &mut Self
Process exactly N pending tasks
Useful when you want to control the order of task execution or test intermediate states.
§Panics
Panics if there are fewer than N pending tasks.
Sourcepub fn expect_model(
&mut self,
predicate: impl FnOnce(&A::Model) -> bool,
) -> &mut Self
pub fn expect_model( &mut self, predicate: impl FnOnce(&A::Model) -> bool, ) -> &mut Self
Sourcepub fn expect_model_msg(
&mut self,
predicate: impl FnOnce(&A::Model) -> bool,
msg: &str,
) -> &mut Self
pub fn expect_model_msg( &mut self, predicate: impl FnOnce(&A::Model) -> bool, msg: &str, ) -> &mut Self
Assert that the model satisfies a predicate with custom message
§Panics
Panics with the provided message if the predicate returns false