tauri-docs
tauri-docs copied to clipboard
Use generic runtime in command examples for testability
Closes tauri-apps/tauri#12077
Description
When writing integration tests for Tauri commands using tauri::test::MockRuntime, directly calling command functions defined simply with app: AppHandle can lead to type mismatch errors (E0308). This occurs because the non-generic signature often defaults to expecting AppHandle<Wry>, while the test provides AppHandle<MockRuntime>.
This commit updates command function examples across the documentation (where AppHandleis used as an argument) to utilize the generic runtime pattern:
async fn command<R: Runtime>(app: AppHandle<R>, state: State<'_, MyState>, ...)
Adopting this generic approach makes command functions compatible with any valid Tauri runtime (R: Runtime), including MockRuntime. This significantly improves testability by allowing developers to call command logic directly in their tests, bypassing potential issues with mock invoke handlers and focusing on verifying function behavior and state interactions.