pub struct RenderHarness { /* private fields */ }Expand description
Test harness for capturing rendered output.
Provides utilities for rendering components to a test buffer and converting the output to strings for snapshot testing.
§Example
ⓘ
use tui_dispatch::testing::RenderHarness;
let mut render = RenderHarness::new(80, 24);
// Render a component
let output = render.render_to_string(|frame| {
my_component.render(frame, frame.area(), props);
});
// Use with insta for snapshot testing
insta::assert_snapshot!(output);Implementations§
Source§impl RenderHarness
impl RenderHarness
Sourcepub fn new(width: u16, height: u16) -> Self
pub fn new(width: u16, height: u16) -> Self
Create a new render harness with the specified dimensions.
Sourcepub fn render<F>(&mut self, render_fn: F) -> &Buffer
pub fn render<F>(&mut self, render_fn: F) -> &Buffer
Render using the provided function and return the buffer.
Sourcepub fn render_to_string<F>(&mut self, render_fn: F) -> String
pub fn render_to_string<F>(&mut self, render_fn: F) -> String
Render and convert the buffer to a string representation.
The output includes ANSI escape codes for colors and styles.
Sourcepub fn render_to_string_plain<F>(&mut self, render_fn: F) -> String
pub fn render_to_string_plain<F>(&mut self, render_fn: F) -> String
Render and convert to a plain string (no ANSI codes).
Useful for simple text assertions without style information.
Auto Trait Implementations§
impl Freeze for RenderHarness
impl RefUnwindSafe for RenderHarness
impl Send for RenderHarness
impl Sync for RenderHarness
impl Unpin for RenderHarness
impl UnwindSafe for RenderHarness
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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 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>
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