All files / expect / _mock_util.ts

0.00% Branches 0/1
62.50% Lines 5/8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
 
 
x101
 
 
 
 
 
 
 
 
 
 
x101
x218
 
 
 
 
x654
x218















I




// Copyright 2018-2025 the Deno authors. MIT license.
// deno-lint-ignore-file no-explicit-any

export const MOCK_SYMBOL = Symbol.for("@MOCK");

export type MockCall = {
  args: any[];
  returned?: any;
  thrown?: any;
  timestamp: number;
  returns: boolean;
  throws: boolean;
};

export function getMockCalls(f: any): MockCall[] {
  const mockInfo = f[MOCK_SYMBOL];
  if (!mockInfo) {
    throw new Error("Received function must be a mock or spy function");
  }

  return [...mockInfo.calls];
}