-
Notifications
You must be signed in to change notification settings - Fork 749
Use generic runtime in command examples for testability #3255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v2
Are you sure you want to change the base?
Conversation
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 `AppHandle` or `State` are used as arguments) to utilize the generic runtime pattern: ```rust 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.
✅ Deploy Preview for tauri-v2 ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
Hey thanks for the work, since this syntax is quite verbose and is only useful for using another tauri runtime (in this case the mock runtime), I think maybe we could add a section/tip for this instead of changing the example like this |
I don't get how adding a generic type parameter to 5 lines within the examples makes it considerably more verbose. It doesn't hurt if people who aren't writing tests use the type parameter, but it does prevent people who are writing tests from running into a completely unhelpful error message. But if you want to do the work to change my PR to your preferred version, @Legend-Master, you're welcome to do so. I was just trying to save your team from some unnecessary GitHub issues. |
There have been quite some confusions around the generics in the past that people don't understand what they do, that's why I don't quite want to add them
This is true though, it's really hard to debug what's going on when you hit that error
I have gone ahead and made the change, do you think this change is fine to you? Since this is where we introduced how to use
I appreciate your effort 🙏 |
Closes tauri-apps/tauri#12077
Description
When writing integration tests for Tauri commands using
tauri::test::MockRuntime
, directly calling command functions defined simply withapp: AppHandle
can lead to type mismatch errors (E0308). This occurs because the non-generic signature often defaults to expectingAppHandle<Wry>
, while the test providesAppHandle<MockRuntime>
.This commit updates command function examples across the documentation (where
AppHandle
is used as an argument) to utilize the generic runtime pattern:Adopting this generic approach makes command functions compatible with any valid Tauri runtime (
R: Runtime
), includingMockRuntime
. 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.