Available on crate feature
test
only.Expand description
Utilities for unit testing on Tauri applications.
§Stability
This module is unstable.
§Examples
use tauri::test::{mock_builder, mock_context, noop_assets};
#[tauri::command]
fn ping() -> &'static str {
"pong"
}
fn create_app<R: tauri::Runtime>(builder: tauri::Builder<R>) -> tauri::App<R> {
builder
.invoke_handler(tauri::generate_handler![ping])
// remove the string argument to use your app's config file
.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(mock_builder());
let webview = tauri::WebviewWindowBuilder::new(&app, "main", Default::default()).build().unwrap();
// run the `ping` command and assert it returns `pong`
let res = tauri::test::get_ipc_response(
&webview,
tauri::webview::InvokeRequest {
cmd: "ping".into(),
callback: tauri::ipc::CallbackFn(0),
error: tauri::ipc::CallbackFn(1),
url: "http://tauri.localhost".parse().unwrap(),
body: tauri::ipc::InvokeBody::default(),
headers: Default::default(),
invoke_key: tauri::test::INVOKE_KEY.to_string(),
},
).map(|b| b.deserialize::<String>().unwrap());
}
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.
- Executes the given IPC message and get the return value.
- Creates a new
Builder
using theMockRuntime
. - Creates a new
crate::Context
for testing. - Creates a new empty
Assets
implementation.