gpui-testing
БесплатноБез исполняемых скриптовНе проверенTesting GPUI applications and components. Use when writing tests, testing async operations, simulating user input, or debugging test failures.
Об этом скилле
GPUI Testing
This skill covers testing patterns for GPUI applications.
Overview
GPUI provides testing utilities for:
- TestAppContext: Test harness for GPUI apps
- Async test execution: with
run_until_parked() - User input simulation: clicks, key presses
- Entity testing: Creating and interacting with test entities
Test Setup
Basic Test Structure
#[cfg(test)]
mod tests {
use super::*;
use gpui::*;
#[gpui::test]
async fn test_my_view(cx: &mut TestAppContext) {
// Test code here
}
}
Creating Test Entities
#[gpui::test]
async fn test_counter(cx: &mut TestAppContext) {
let counter = cx.new(|_| Counter { count: 0 });
assert_eq!(counter.read(cx).count, 0);
}
Async Testing
Using run_until_parked
#[gpui::test]
async fn test_async_operation(cx: &mut TestAppContext) {
let view = cx.new(|_| MyView::new());
view.update(cx, |view, cx| {
view.start_async_work(cx);
});
// Wait for all async work to complete
cx.background_executor.run_until_parked();
// Check results
assert_eq!(view.read(cx).status, "Complete");
}
GPUI Timers in Tests
IMPORTANT: Use GPUI executor timers, not smol::Timer:
#[gpui::test]
async fn test_with_delay(cx: &mut TestAppContext) {
let view = cx.new(|_| MyView::new());
// ✅ CORRECT - Use GPUI timer
cx.background_executor.timer(Duration::from_secs(1)).await;
// ❌ WRONG - Don't use smol::Timer
// smol::Timer::after(Duration::from_secs(1)).await;
cx.background_executor.run_until_parked();
}
Why: GPUI's scheduler tracks GPUI timers but not smol::Timer, which can cause "nothing left to run" errors in run_until_parked().
Testing Entity Updates
Update and Verify
#[gpui::test]
async fn test_increment(cx: &mut TestAppContext) {
let counter = cx.new(|_| Counter { count: 0 });
counter.update(cx, |counter, cx| {
counter.increment(cx);
});
assert_eq!(counter.read(cx).count, 1);
}
Testing Notify
#[gpui::test]
async fn test_notify(cx: &mut TestAppContext) {
let view = cx.new(|_| MyView::new());
let observed = Arc::new(AtomicBool::new(false));
let observed_clone = observed.clone();
cx.observe(&view, move |_view, _cx| {
observed_clone.store(true, Ordering::SeqCst);
});
view.update(cx, |view, cx| {
view.data = "changed".into();
cx.notify();
});
assert!(observed.load(Ordering::SeqCst));
}
Testing Actions
Dispatching Actions
actions!(test, [TestAction]);
#[gpui::test]
async fn test_action_handling(cx: &mut TestAppContext) {
let view = cx.new(|_| MyView::new());
// Simulate action dispatch
view.update(cx, |view, cx| {
view.handle_action(&TestAction, cx);
});
assert_eq!(view.read(cx).action_count, 1);
}
Testing Subscriptions
Event Emission
#[derive(Clone, Debug)]
enum MyEvent {
ValueChanged(i32),
}
impl EventEmitter<MyEvent> for MyView {}
#[gpui::test]
async fn test_event_emission(cx: &mut TestAppContext) {
let view = cx.new(|_| MyView::new());
let received_events = Arc::new(Mutex::new(Vec::new()));
let events_clone = received_events.clone();
cx.subscribe(&view, move |_this, _emitter, event, _cx| {
events_clone.lock().unwrap().push(event.clone());
});
view.update(cx, |view, cx| {
cx.emit(MyEvent::ValueChanged(42));
});
let events = received_events.lock().unwrap();
assert_eq!(events.len(), 1);
}
Testing Async Operations
Background Task Completion
#[gpui::test]
async fn test_background_task(cx: &mut TestAppContext) {
let view = cx.new(|_| MyView::new());
view.update(cx, |view, cx| {
cx.spawn(async move |this, cx| {
let result = cx.background_spawn(async {
// Expensive computation
42
}).await;
this.update(&mut *cx, |view, cx| {
view.result = Some(result);
cx.notify();
})?;
Ok(())
}).detach();
});
// Wait for all async work
cx.background_executor.run_until_parked();
assert_eq!(view.read(cx).result, Some(42));
}
Testing Task Cancellation
#[gpui::test]
async fn test_task_cancellation(cx: &mut TestAppContext) {
let view = cx.new(|_| MyView::new());
view.update(cx, |view, cx| {
view.start_long_task(cx);
});
// Cancel task
view.update(cx, |view, cx| {
view.cancel_task();
});
cx.background_executor.run_until_parked();
// Task should not have completed
assert_eq!(view.read(cx).task_completed, false);
}
Assertions and Expectations
Entity State Assertions
#[g
Установить gpui-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл gpui-testing?
Testing GPUI applications and components. Use when writing tests, testing async operations, simulating user input, or debugging test failures.
Как установить скилл gpui-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл gpui-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic