Function tauri::test::get_ipc_response
source · pub fn get_ipc_response<T: DeserializeOwned + Debug>(
window: &Window<MockRuntime>,
payload: InvokePayload
) -> Result<T, T>
Available on crate feature
test
only.Expand description
The application processes the command and stops.
§Examples
#[tauri::command]
fn ping() -> &'static str {
"pong"
}
fn create_app<R: tauri::Runtime>(mut builder: tauri::Builder<R>) -> tauri::App<R> {
builder
.invoke_handler(tauri::generate_handler![ping])
// remove the string argument on your app
.build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
.expect("failed to build app")
}
use tauri::test::*;
use tauri::Manager;
let app = create_app(mock_builder());
let window = app.get_window("main").unwrap();
// run the `ping` command and assert it returns `pong`
let res = tauri::test::get_ipc_response::<String>(
&window,
tauri::InvokePayload {
cmd: "ping".into(),
tauri_module: None,
callback: tauri::api::ipc::CallbackFn(0),
error: tauri::api::ipc::CallbackFn(1),
inner: serde_json::Value::Null,
});
assert_eq!(res, Ok("pong".into()))