@@ -2,86 +2,11 @@ import type { QuickPickItem, window, Uri } from "vscode";
22import type { DatabaseItem } from "../../../src/databases/local-databases" ;
33import type { Octokit } from "@octokit/rest" ;
44
5- export type DeepPartial < T > = T extends object
6- ? {
7- [ P in keyof T ] ?: DeepPartial < T [ P ] > ;
8- }
9- : T ;
5+ import type { DeepPartial } from "../../mocked-object" ;
6+ import { mockedObject } from "../../mocked-object" ;
107
11- type DynamicProperties < T extends object > = {
12- [ P in keyof T ] ?: ( ) => T [ P ] ;
13- } ;
14-
15- type MockedObjectOptions < T extends object > = {
16- /**
17- * Properties for which the given method should be called when accessed.
18- * The method should return the value to be returned when the property is accessed.
19- * Methods which are explicitly defined in `methods` will take precedence over
20- * dynamic properties.
21- */
22- dynamicProperties ?: DynamicProperties < T > ;
23- } ;
24-
25- export function mockedObject < T extends object > (
26- props : DeepPartial < T > ,
27- { dynamicProperties } : MockedObjectOptions < T > = { } ,
28- ) : T {
29- return new Proxy < T > ( { } as unknown as T , {
30- get : ( _target , prop ) => {
31- if ( prop in props ) {
32- return ( props as any ) [ prop ] ;
33- }
34- if ( dynamicProperties && prop in dynamicProperties ) {
35- return ( dynamicProperties as any ) [ prop ] ( ) ;
36- }
37-
38- // The `then` method is accessed by `Promise.resolve` to check if the object is a thenable.
39- // We don't want to throw an error when this happens.
40- if ( prop === "then" ) {
41- return undefined ;
42- }
43-
44- // The `asymmetricMatch` is accessed by jest to check if the object is a matcher.
45- // We don't want to throw an error when this happens.
46- if ( prop === "asymmetricMatch" ) {
47- return undefined ;
48- }
49-
50- // The `Symbol.iterator` is accessed by jest to check if the object is iterable.
51- // We don't want to throw an error when this happens.
52- if ( prop === Symbol . iterator ) {
53- return undefined ;
54- }
55-
56- // The `$$typeof` is accessed by jest to check if the object is a React element.
57- // We don't want to throw an error when this happens.
58- if ( prop === "$$typeof" ) {
59- return undefined ;
60- }
61-
62- // The `nodeType` and `tagName` are accessed by jest to check if the object is a DOM node.
63- // We don't want to throw an error when this happens.
64- if ( prop === "nodeType" || prop === "tagName" ) {
65- return undefined ;
66- }
67-
68- // The `@@__IMMUTABLE_ITERABLE__@@` and variants are accessed by jest to check if the object is an
69- // immutable object (from Immutable.js).
70- // We don't want to throw an error when this happens.
71- if ( prop . toString ( ) . startsWith ( "@@__IMMUTABLE_" ) ) {
72- return undefined ;
73- }
74-
75- // The `Symbol.toStringTag` is accessed by jest.
76- // We don't want to throw an error when this happens.
77- if ( prop === Symbol . toStringTag ) {
78- return "MockedObject" ;
79- }
80-
81- throw new Error ( `Method ${ String ( prop ) } not mocked` ) ;
82- } ,
83- } ) ;
84- }
8+ export { mockedObject } ;
9+ export type { DeepPartial } ;
8510
8611export function mockedOctokitFunction <
8712 Namespace extends keyof Octokit [ "rest" ] ,
0 commit comments