Function mockSession
- mock
Session (): number Returns number
The id of the created session.
Example: Usage
import { mockSession, restore, stub } from "@std/testing/mock";
import { assertEquals, assertNotEquals } from "@std/assert";
const setTimeout = globalThis.setTimeout;
const id = mockSession();
stub(globalThis, "setTimeout");
assertNotEquals(globalThis.setTimeout, setTimeout);
restore(id);
assertEquals(globalThis.setTimeout, setTimeout);- mock
Session <Self, Args, Return>(func): ((this: Self, ...args: Args) => Return) Creates a session that tracks all mocks created before it's restored. If a callback is provided, it restores all mocks created within it.
Type Parameters
Parameters
Returns ((this: Self, ...args: Args) => Return)
The function to execute the session.
Example: Usage
import { mockSession, restore, stub } from "@std/testing/mock";
import { assertEquals, assertNotEquals } from "@std/assert";
const setTimeout = globalThis.setTimeout;
const session = mockSession(() => {
stub(globalThis, "setTimeout");
assertNotEquals(globalThis.setTimeout, setTimeout);
});
session();
assertEquals(globalThis.setTimeout, setTimeout); // stub is restored
Creates a session that tracks all mocks created before it's restored. If a callback is provided, it restores all mocks created within it.