Skip to content

Instantly share code, notes, and snippets.

Created September 3, 2023 17:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Tauri-demo first meaningful test
import './main';
import { mockIPC } from "@tauri-apps/api/mocks";
describe('main', () => {
it('should set the greeting message inside the message element', async () => {
document.body.innerHTML = `
<form id="greet-form">
<input id="greet-input" />
<div id="greet-msg"></div>
window.dispatchEvent(new Event("DOMContentLoaded"));
const name = 'John Doe';
const greetInputEl = document.querySelector("#greet-input") as HTMLInputElement;
const greetMsgEl = document.querySelector("#greet-msg");
const greetForm = document.querySelector("#greet-form") as HTMLFormElement;
greetInputEl.value = name;
mockIPC((cmd, args) => {
if(cmd === "greet") {
return `Hello, ${}! You've been greeted from Rust!`;
greetForm.dispatchEvent(new Event("submit"));
await new Promise((resolve) => setTimeout(resolve, 0));
expect(greetMsgEl?.textContent).toBe(`Hello, ${name}! You've been greeted from Rust!`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment