Module tauri::test

source ·
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() {
  // let app = create_app(tauri::Builder::default());
  // 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::window::InvokeRequest {
        cmd: "my_cmd".into(),
        callback: tauri::ipc::CallbackFn(0),
        error: tauri::ipc::CallbackFn(1),
        body: serde_json::Value::Null.into(),
        headers: Default::default(),
      },
      Ok(())
    );
  }
}

Structs

Functions