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() {
let app = create_app(mock_builder());
let window = tauri::WindowBuilder::new(&app, "main", Default::default())
.build()
.unwrap();
// run the `ping` command and assert it returns `pong`
let res = tauri::test::get_ipc_response(
&window,
tauri::window::InvokeRequest {
cmd: "ping".into(),
callback: tauri::ipc::CallbackFn(0),
error: tauri::ipc::CallbackFn(1),
body: tauri::ipc::InvokeBody::default(),
headers: Default::default(),
},
).map(|b| b.deserialize::<String>().unwrap());
}
Structs
- An empty
Assets
implementation.
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.