Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Created September 3, 2023 17:59
Show Gist options
  • Save YonatanKra/3b0ea47536296adabae1551d160bb432 to your computer and use it in GitHub Desktop.
Save YonatanKra/3b0ea47536296adabae1551d160bb432 to your computer and use it in GitHub Desktop.
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" />
</form>
<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, ${args.name}! 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