Available on crate feature
test
only.Expand description
Utilities for unit testing on Tauri applications.
§Stability
This module is unstable.
§Examples
#[tauri::command]
fn my_cmd() {}
fn create_app<R: tauri::Runtime>(mut builder: tauri::Builder<R>) -> tauri::App<R> {
builder
.setup(|app| {
// do something
Ok(())
})
.invoke_handler(tauri::generate_handler![my_cmd])
// remove the string argument on your app
.build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
.expect("failed to build app")
}
fn main() {
// Use `tauri::Builder::default()` to use the default runtime rather than the `MockRuntime`;
// let app = create_app(tauri::Builder::default());
let app = create_app(tauri::test::mock_builder());
// app.run(|_handle, _event| {});
}
//#[cfg(test)]
mod tests {
use tauri::Manager;
//#[cfg(test)]
fn something() {
let app = super::create_app(tauri::test::mock_builder());
let window = app.get_window("main").unwrap();
// do something with the app and window
// in this case we'll run the my_cmd command with no arguments
tauri::test::assert_ipc_response(
&window,
tauri::InvokePayload {
cmd: "my_cmd".into(),
tauri_module: None,
callback: tauri::api::ipc::CallbackFn(0),
error: tauri::api::ipc::CallbackFn(1),
inner: serde_json::Value::Null,
invoke_key: Some(tauri::test::INVOKE_KEY.into()),
},
Ok(())
);
}
}
Structs§
- An empty
Assets
implementation.
Constants§
- The invoke key used for tests.
Functions§
- Executes the given IPC message and assert the response matches the expected value.
- The application processes the command and stops.
- Creates a new
Builder
using theMockRuntime
. - Creates a new
crate::Context
for testing. - Creates a new empty
Assets
implementation.