From 8e98e1c37a6b8c7a69f5339c1ed411cf1fd89715 Mon Sep 17 00:00:00 2001 From: Duncan Tourolle Date: Sun, 16 Aug 2026 21:20:55 +0200 Subject: [PATCH] test(player): answer the commands the tap-surface tests actually render MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit VideoPlayer.tapSurface.test.ts deliberately does not mock $lib/api/bindings — it renders the real component against the real bindings, which bottom out in the globally mocked `invoke`. That mock resolves `undefined` for every command, so any command whose result is *rendered* blows up: the quality picker assigns the result straight to state and the template then reads `streamingQualities.length`, which throws on undefined. It threw asynchronously, outside any test, so the suite reported 4 unhandled errors while every test still passed — the state vitest warns "might cause false positive tests". Answering the two rendered commands removes them. Authored in the main checkout; brought in here and verified: 83 files, 1009 tests, and the unhandled-error count drops from 4 to 0. --- .../player/VideoPlayer.tapSurface.test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib/components/player/VideoPlayer.tapSurface.test.ts b/src/lib/components/player/VideoPlayer.tapSurface.test.ts index 30fd09fd..86bd91a4 100644 --- a/src/lib/components/player/VideoPlayer.tapSurface.test.ts +++ b/src/lib/components/player/VideoPlayer.tapSurface.test.ts @@ -32,6 +32,7 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; import { render } from "@testing-library/svelte"; import { tick } from "svelte"; +import { invoke } from "@tauri-apps/api/core"; import VideoPlayer from "./VideoPlayer.svelte"; import { SEEK_FORWARD_SECONDS } from "./tapGestures"; @@ -128,6 +129,23 @@ function renderPlayer() { describe("VideoPlayer tap surface (real component)", () => { beforeEach(() => { vi.clearAllMocks(); + // This file deliberately does NOT mock `$lib/api/bindings` — it renders the + // real component against the real bindings, which bottom out in the globally + // mocked `invoke`. That mock resolves `undefined` for every command, so the + // commands whose results are *rendered* have to be answered here: the + // quality picker assigns the result straight to state and then does + // `streamingQualities.length` in the template, which throws (asynchronously, + // outside any test) on undefined and fails the run with an unhandled error. + vi.mocked(invoke).mockImplementation(async (cmd: string) => { + switch (cmd) { + case "player_get_streaming_qualities": + return []; + case "player_get_video_settings": + return { streamingQuality: "original" }; + default: + return undefined; + } + }); }); it("a single tap on the video toggles play/pause exactly once", async () => {