Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.d.ts 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. export declare type MockFunctionMetadataType = 'object' | 'array' | 'regexp' | 'function' | 'constant' | 'collection' | 'null' | 'undefined';
  8. export declare type MockFunctionMetadata<T, Y extends Array<unknown>, Type = MockFunctionMetadataType> = {
  9. ref?: number;
  10. members?: Record<string, MockFunctionMetadata<T, Y>>;
  11. mockImpl?: (...args: Y) => T;
  12. name?: string;
  13. refID?: number;
  14. type?: Type;
  15. value?: T;
  16. length?: number;
  17. };
  18. export interface Mock<T, Y extends Array<unknown> = Array<unknown>> extends Function, MockInstance<T, Y> {
  19. new (...args: Y): T;
  20. (...args: Y): T;
  21. }
  22. export interface SpyInstance<T, Y extends Array<unknown>> extends MockInstance<T, Y> {
  23. }
  24. export interface MockInstance<T, Y extends Array<unknown>> {
  25. _isMockFunction: true;
  26. _protoImpl: Function;
  27. getMockName(): string;
  28. getMockImplementation(): Function | undefined;
  29. mock: MockFunctionState<T, Y>;
  30. mockClear(): this;
  31. mockReset(): this;
  32. mockRestore(): void;
  33. mockImplementation(fn: (...args: Y) => T): this;
  34. mockImplementation(fn: () => Promise<T>): this;
  35. mockImplementationOnce(fn: (...args: Y) => T): this;
  36. mockImplementationOnce(fn: () => Promise<T>): this;
  37. mockName(name: string): this;
  38. mockReturnThis(): this;
  39. mockReturnValue(value: T): this;
  40. mockReturnValueOnce(value: T): this;
  41. mockResolvedValue(value: Unpromisify<T>): this;
  42. mockResolvedValueOnce(value: Unpromisify<T>): this;
  43. mockRejectedValue(value: unknown): this;
  44. mockRejectedValueOnce(value: unknown): this;
  45. }
  46. declare type Unpromisify<T> = T extends Promise<infer R> ? R : never;
  47. /**
  48. * Possible types of a MockFunctionResult.
  49. * 'return': The call completed by returning normally.
  50. * 'throw': The call completed by throwing a value.
  51. * 'incomplete': The call has not completed yet. This is possible if you read
  52. * the mock function result from within the mock function itself
  53. * (or a function called by the mock function).
  54. */
  55. declare type MockFunctionResultType = 'return' | 'throw' | 'incomplete';
  56. /**
  57. * Represents the result of a single call to a mock function.
  58. */
  59. declare type MockFunctionResult = {
  60. /**
  61. * Indicates how the call completed.
  62. */
  63. type: MockFunctionResultType;
  64. /**
  65. * The value that was either thrown or returned by the function.
  66. * Undefined when type === 'incomplete'.
  67. */
  68. value: unknown;
  69. };
  70. declare type MockFunctionState<T, Y extends Array<unknown>> = {
  71. calls: Array<Y>;
  72. instances: Array<T>;
  73. invocationCallOrder: Array<number>;
  74. /**
  75. * List of results of calls to the mock function.
  76. */
  77. results: Array<MockFunctionResult>;
  78. };
  79. declare type NonFunctionPropertyNames<T> = {
  80. [K in keyof T]: T[K] extends (...args: Array<any>) => any ? never : K;
  81. }[keyof T] & string;
  82. declare type FunctionPropertyNames<T> = {
  83. [K in keyof T]: T[K] extends (...args: Array<any>) => any ? K : never;
  84. }[keyof T] & string;
  85. export declare class ModuleMocker {
  86. private _environmentGlobal;
  87. private _mockState;
  88. private _mockConfigRegistry;
  89. private _spyState;
  90. private _invocationCallCounter;
  91. /**
  92. * @see README.md
  93. * @param global Global object of the test environment, used to create
  94. * mocks
  95. */
  96. constructor(global: typeof globalThis);
  97. private _getSlots;
  98. private _ensureMockConfig;
  99. private _ensureMockState;
  100. private _defaultMockConfig;
  101. private _defaultMockState;
  102. private _makeComponent;
  103. private _createMockFunction;
  104. private _generateMock;
  105. /**
  106. * @see README.md
  107. * @param _metadata Metadata for the mock in the schema returned by the
  108. * getMetadata method of this module.
  109. */
  110. generateFromMetadata<T, Y extends Array<unknown>>(_metadata: MockFunctionMetadata<T, Y>): Mock<T, Y>;
  111. /**
  112. * @see README.md
  113. * @param component The component for which to retrieve metadata.
  114. */
  115. getMetadata<T, Y extends Array<unknown>>(component: T, _refs?: Map<T, number>): MockFunctionMetadata<T, Y> | null;
  116. isMockFunction<T>(fn: unknown): fn is Mock<T>;
  117. fn<T, Y extends Array<unknown>>(implementation?: (...args: Y) => T): Mock<T, Y>;
  118. spyOn<T extends {}, M extends NonFunctionPropertyNames<T>>(object: T, methodName: M, accessType: 'get'): SpyInstance<T[M], []>;
  119. spyOn<T extends {}, M extends NonFunctionPropertyNames<T>>(object: T, methodName: M, accessType: 'set'): SpyInstance<void, [T[M]]>;
  120. spyOn<T extends {}, M extends FunctionPropertyNames<T>>(object: T, methodName: M): T[M] extends (...args: Array<any>) => any ? SpyInstance<ReturnType<T[M]>, Parameters<T[M]>> : never;
  121. private _spyOnProperty;
  122. clearAllMocks(): void;
  123. resetAllMocks(): void;
  124. restoreAllMocks(): void;
  125. private _typeOf;
  126. }
  127. export declare const fn: <T, Y extends unknown[]>(implementation?: ((...args: Y) => T) | undefined) => Mock<T, Y>;
  128. export declare const spyOn: {
  129. <T extends {}, M extends NonFunctionPropertyNames<T>>(object: T, methodName: M, accessType: 'get'): SpyInstance<T[M], []>;
  130. <T_2 extends {}, M_2 extends NonFunctionPropertyNames<T_2>>(object: T_2, methodName: M_2, accessType: 'set'): SpyInstance<void, [T_2[M_2]]>;
  131. <T_4 extends {}, M_4 extends FunctionPropertyNames<T_4>>(object: T_4, methodName: M_4): T_4[M_4] extends (...args: Array<any>) => any ? SpyInstance<ReturnType<T_4[M_4]>, Parameters<T_4[M_4]>> : never;
  132. };
  133. export {};