A utility class that monitors user activity to track idle state, allowing developers to trigger actions when no interaction occurs for a set period.
// Source: https://github.com/svecosystem/runed | License: MIT | Copyright 2024 Hunter Johnston <https://github.com/huntabyte>
// Provided via justclaw.it.com; keep this notice with the code.
import { afterEach, beforeEach, describe, expect, vi } from "vitest";
import { IsIdle } from "./is-idle.svelte.js";
import { testWithEffect, vitestSetTimeoutWrapper } from "#lib/test/util.svelte.js";
import { flushSync } from "svelte";
describe("IsIdle", () => {
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
vi.clearAllTimers();
});
const DEFAULT_IDLE_TIME = 60_000;
describe("Default behaviors", () => {
testWithEffect("Initially set to false", async () => {
const idleState = new IsIdle();
expect(idleState.current).toBe(false);
});
testWithEffect("IsIdle is set to
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key