File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " api " : patch
3+ ---
4+
5+ Update ` mockIPC() ` handler signature to allow async handler functions.
Original file line number Diff line number Diff line change @@ -35,10 +35,31 @@ interface IPCMessage {
3535 * })
3636 * ```
3737 *
38+ * The callback function can also return a Promise:
39+ * ```js
40+ * import { mockIPC, clearMocks } from "@tauri-apps/api/mocks"
41+ * import { invoke } from "@tauri-apps/api/tauri"
42+ *
43+ * afterEach(() => {
44+ * clearMocks()
45+ * })
46+ *
47+ * test("mocked command", () => {
48+ * mockIPC((cmd, args) => {
49+ * if(cmd === "get_data") {
50+ * return fetch("https://example.com/data.json")
51+ * .then((response) => response.json())
52+ * }
53+ * });
54+ *
55+ * expect(invoke('get_data')).resolves.toBe({ foo: 'bar' });
56+ * })
57+ * ```
58+ *
3859 * @param cb
3960 */
4061export function mockIPC (
41- cb : ( cmd : string , args : Record < string , unknown > ) => any
62+ cb : ( cmd : string , args : Record < string , unknown > ) => any | Promise < any >
4263) : void {
4364 // eslint-disable-next-line @typescript-eslint/no-misused-promises
4465 window . __TAURI_IPC__ = async ( {
You can’t perform that action at this time.
0 commit comments