MCPcopy Create free account
hub / github.com/denoland/std / mockSession

Function mockSession

testing/mock.ts:510–531  ·  view source on GitHub ↗
(
  func?: (this: Self, ...args: Args) => Return,
)

Source from the content-addressed store, hash-verified

508 func: (this: Self, ...args: Args) => Return,
509): (this: Self, ...args: Args) => Return;
510export function mockSession<
511 Self,
512 Args extends unknown[],
513 Return,
514>(
515 func?: (this: Self, ...args: Args) => Return,
516): number | ((this: Self, ...args: Args) => Return) {
517 if (func) {
518 return function (this: Self, ...args: Args): Return {
519 const id = sessions.length;
520 sessions.push(new Set());
521 try {
522 return func.apply(this, args);
523 } finally {
524 restore(id);
525 }
526 };
527 } else {
528 sessions.push(new Set());
529 return sessions.length - 1;
530 }
531}
532
533/**
534 * Creates an async session that tracks all mocks created before the promise resolves.

Callers 1

mock_test.tsFile · 0.90

Calls 2

restoreFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected