Loading...
Loading...
Writing tests for GPUI applications. Use when testing components, async operations, or UI behavior.
npx skill4agent add longbridge/gpui-component gpui-test#[gpui::test]TestAppContextVisualTestContext[gpui::test]TestAppContext#[gpui::test]
fn my_test(cx: &mut TestAppContext) {
// Test implementation
}#[gpui::test]
async fn my_async_test(cx: &mut TestAppContext) {
// Async test implementation
}#[gpui::test(iterations = 10)]
fn my_property_test(cx: &mut TestAppContext, mut rng: StdRng) {
// Property testing with random data
}TestAppContext#[gpui::test]
fn test_entity_operations(cx: &mut TestAppContext) {
// Create entities
let entity = cx.new(|cx| MyComponent::new(cx));
// Update entities
entity.update(cx, |component, cx| {
component.value = 42;
cx.notify();
});
// Read entities
let value = entity.read_with(cx, |component, _| component.value);
assert_eq!(value, 42);
}VisualTestContextTestAppContext#[gpui::test]
fn test_with_window(cx: &mut TestAppContext) {
// Create window with component
let window = cx.update(|cx| {
cx.open_window(Default::default(), |_, cx| {
cx.new(|cx| MyComponent::new(cx))
}).unwrap()
});
// Convert to visual context
let mut cx = VisualTestContext::from_window(window.into(), cx);
// Access window and component
let component = window.root(&mut cx).unwrap();
}