eslint now also enforces: - the React Compiler diagnostics that `recommended` leaves out (todo, memo-dependencies and ten zero-hit tripwires); - a description on every suppression, and no blanket disables; - no focused or skipped tests (vitest and playwright); - the typed pair no-floating-promises and no-deprecated. Lint also covers e2e/ and the TypeScript build configs, which `eslint .` had been skipping in silence. Every hit is fixed or suppressed inline with a named reason: - The 31 try statements the compiler cannot lower yet carry a suppression until S3 rewrites them. Five other compiler skips were plain fixes: a module counter bumped inside a hook, a ref read in a default parameter, and a local named like the <section> it renders. - The real defects behind floating promises are fixed. ChatDock threw at nobody when the device key store could not be opened. VideoEditor's play() rejection went unhandled. loadYouTubeApi never rejected, so a blocked IFrame API left the player on an empty stage forever; it now fails on a script error or after 15 s, shows its own error with the way out, and lets the next open try again. - MutableRefObject, FormEvent and lucide's deprecated brand icon are replaced. The YouTube glyph now lives in lib/brandIcons. - The lint-probe harness lets its virtual file names into TypeScript's default project, so the contract tests still run the real config.
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { act, renderHook } from "@testing-library/react";
|
|
|
|
import { useDebounced } from "./useDebounced";
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
describe("useDebounced", () => {
|
|
it("hands a value on once it stopped changing for the delay", () => {
|
|
vi.useFakeTimers();
|
|
const { result, rerender } = renderHook(({ v }) => useDebounced(v, 300), {
|
|
initialProps: { v: "a" },
|
|
});
|
|
rerender({ v: "ab" });
|
|
expect(result.current).toBe("a");
|
|
act(() => {
|
|
vi.advanceTimersByTime(300);
|
|
});
|
|
expect(result.current).toBe("ab");
|
|
});
|
|
|
|
it("takes the value at once when `settle` changes — a jump, not typing", () => {
|
|
vi.useFakeTimers();
|
|
const { result, rerender } = renderHook(({ v, s }) => useDebounced(v, 300, s), {
|
|
initialProps: { v: "", s: 0 },
|
|
});
|
|
rerender({ v: "boom", s: 1 });
|
|
expect(result.current).toBe("boom");
|
|
rerender({ v: "boomx", s: 1 });
|
|
expect(result.current).toBe("boom");
|
|
act(() => {
|
|
vi.advanceTimersByTime(300);
|
|
});
|
|
expect(result.current).toBe("boomx");
|
|
});
|
|
});
|