Function mockSessionAsync
- mock
Session <Self, Args, Return>(func): ((this: Self, ...args: Args) => Promise<Return>)Async Type Parameters
Parameters
Returns ((this: Self, ...args: Args) => Promise<Return>)
The return value of the function.
Example: Usage
import { mockSessionAsync, restore, stub } from "@std/testing/mock";
import { assertEquals, assertNotEquals } from "@std/assert";
const setTimeout = globalThis.setTimeout;
const session = mockSessionAsync(async () => {
stub(globalThis, "setTimeout");
assertNotEquals(globalThis.setTimeout, setTimeout);
});
await session();
assertEquals(globalThis.setTimeout, setTimeout); // stub is restored
Creates an async session that tracks all mocks created before the promise resolves.